语法和解析错误

发布于 2024-10-22 06:08:29 字数 1644 浏览 1 评论 0原文

我在第 9 行不断收到语法错误,并在第 31、32、33 和 38 行收到解析错误……我不知道为什么。谁能帮助我吗?

#include stdio.h<> <-----there are all correct in the code but don't show on here
#include stdlib.h<>
#include math.h<> 

int hamlength;
int pbit;
int hamcode;

String char  *hamming = NULL;

void enter_params(){
    printf("Enter length of the Hamming code:_\n");
      scanf("%d",&hamlength);
 printf("Enter the parity(0=even, 1=odd):_\n");
      scanf("%d",&pbit);
    hamming = (char *)malloc(hamlength * sizeof(char));
}

void free_memory(){
if (hamming != NULL)
    free (hamming);
return;
}

 1. List item

void correct_hamming(){
int errorBit=0;
int currentBit;
int i;
int j;
int k;
printf("Enter the Hamming Code:_\n");
scanf("%s", hamming);
for(i = 1, i < hamlength; i = i * 2){
for(j = i; j < hamlength; j += 2 * i){
for(k = j; k < hamlength && k < currentBit; k++){
        currentBit = currentBit ^ hamming [hamlength - k];
        if (k != i)
        currentBit = currentBit ^ hamming[hamlength - k];       
}
errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);
}
}
}
int main(){
      int choice=0;
      while(choice!=3){
         printf("1) Set parameters\n");
         printf("2) Check Hamming Code\n");
         printf("3) Exit\n");        
         printf("Enter selection:_\n");
            scanf("%d",&choice);
         switch(choice){
            case 1: enter_params(); 
               break; 
            case 2:  correct_hamming();
               break;
           case 3: printf("dueces!");
                    break;


         }
      }
      return 0;
   }

i keep getting a syntax error on line 9 and parse errors on lines 31, 32, 33, and 38...and i dont know why. Can anyone help me?

#include stdio.h<> <-----there are all correct in the code but don't show on here
#include stdlib.h<>
#include math.h<> 

int hamlength;
int pbit;
int hamcode;

String char  *hamming = NULL;

void enter_params(){
    printf("Enter length of the Hamming code:_\n");
      scanf("%d",&hamlength);
 printf("Enter the parity(0=even, 1=odd):_\n");
      scanf("%d",&pbit);
    hamming = (char *)malloc(hamlength * sizeof(char));
}

void free_memory(){
if (hamming != NULL)
    free (hamming);
return;
}

 1. List item

void correct_hamming(){
int errorBit=0;
int currentBit;
int i;
int j;
int k;
printf("Enter the Hamming Code:_\n");
scanf("%s", hamming);
for(i = 1, i < hamlength; i = i * 2){
for(j = i; j < hamlength; j += 2 * i){
for(k = j; k < hamlength && k < currentBit; k++){
        currentBit = currentBit ^ hamming [hamlength - k];
        if (k != i)
        currentBit = currentBit ^ hamming[hamlength - k];       
}
errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);
}
}
}
int main(){
      int choice=0;
      while(choice!=3){
         printf("1) Set parameters\n");
         printf("2) Check Hamming Code\n");
         printf("3) Exit\n");        
         printf("Enter selection:_\n");
            scanf("%d",&choice);
         switch(choice){
            case 1: enter_params(); 
               break; 
            case 2:  correct_hamming();
               break;
           case 3: printf("dueces!");
                    break;


         }
      }
      return 0;
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

似最初 2024-10-29 06:08:29
#include stdio.h<> <-----there are all correct in the code but don't show on here
#include stdlib.h<>
#include math.h<> 

你的意思是

#include <stdio.h> 
#include <stdlib.h>
#include <math.h> 

String char *hamming = NULL;

String在这里做什么?它不是 C 关键字。从该行中删除 String
你的代码充满了语法和逻辑错误。


 1. List item // should be commented

errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);

这里的拼写错误 currenttBit 应该是 currentBit


for(i = 1, i < i = i * 2)

, 替换为 ;


main() 函数中

  int choice=0;
  while(choice!=3)

将 用户输入他的选择?

#include stdio.h<> <-----there are all correct in the code but don't show on here
#include stdlib.h<>
#include math.h<> 

You meant

#include <stdio.h> 
#include <stdlib.h>
#include <math.h> 

?

String char *hamming = NULL;

What is String doing here? It is not a C keyword. Remove String from that line.
Your code is full of syntax and logic errors.


 1. List item // should be commented

errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);

Typo here currenttBit should be currentBit


for(i = 1, i < hamlength; i = i * 2)

Replace , with ;


In main() function

  int choice=0;
  while(choice!=3)

When would the user enter his choice?

记忆で 2024-10-29 06:08:29

String char * 对我来说看起来不正确。您可能无意在其中包含 String

String char * doesn't look right to me. You probably didn't mean to include String there.

宫墨修音 2024-10-29 06:08:29

删除第 9 行上的“String”。

并更改此行:

for(i = 1, i < hamlength; i = i * 2){

对此,

for(i = 1; i < hamlength; i = i * 2){

我假设在您的代码中“1.List item”并不真正存在。

Remove the "String" on line 9.

And change this line:

for(i = 1, i < hamlength; i = i * 2){

To this

for(i = 1; i < hamlength; i = i * 2){

I'm assuming that in your code "1. List item" isn't really there.

锦爱 2024-10-29 06:08:29
#include<stdio.h>    // this is the right way to include header files
#include<stdlib.h>
#include<math.h> 

String 不是 String char *hamming = NULL; 中 C 的有效关键字/数据类型

1.列表项 在 C 中无效。

#include<stdio.h>    // this is the right way to include header files
#include<stdlib.h>
#include<math.h> 

String is not valid keyword/datatype of C in String char *hamming = NULL;

1. List item is not valid in C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文