gpt4 book ai didi

c - 语法和解析错误

转载 作者:行者123 更新时间:2023-11-30 14:28:59 25 4
gpt4 key购买 nike

我在第 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;
}

最佳答案

#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应该是当前位

<小时/>

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

替换,;

<小时/>

main()功能

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

用户什么时候会输入他的选择?

关于c - 语法和解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5334846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com