语法和解析错误
我在第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你的意思是
?
String char *hamming = NULL;
String
在这里做什么?它不是 C 关键字。从该行中删除String
。你的代码充满了语法和逻辑错误。
errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);
这里的拼写错误
currenttBit
应该是 currentBitfor(i = 1, i < i = i * 2)
,
替换为;
在
main()
函数中将 用户输入他的选择?
You meant
?
String char *hamming = NULL;
What is
String
doing here? It is not a C keyword. RemoveString
from that line.Your code is full of syntax and logic errors.
errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);
Typo here
currenttBit
should be currentBitfor(i = 1, i < hamlength; i = i * 2)
Replace
,
with;
In
main()
functionWhen would the user enter his choice?
String char *
对我来说看起来不正确。您可能无意在其中包含String
。String char *
doesn't look right to me. You probably didn't mean to includeString
there.删除第 9 行上的“String”。
并更改此行:
对此,
我假设在您的代码中“1.List item”并不真正存在。
Remove the "String" on line 9.
And change this line:
To this
I'm assuming that in your code "1. List item" isn't really there.
String
不是String char *hamming = NULL;
中 C 的有效关键字/数据类型1.列表项
在 C 中无效。String
is not valid keyword/datatype of C inString char *hamming = NULL;
1. List item
is not valid in C.