[英]syntax and parse error
我一直在第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);
Typo這里currenttBit
應該是currentBit
for(i = 1, i < hamlength; i = i * 2)
替換,
用;
在main()
函數中
int choice=0;
while(choice!=3)
用戶什么時候輸入他的選擇?
#include<stdio.h> // this is the right way to include header files
#include<stdlib.h>
#include<math.h>
String
不是C中的C的有效關鍵字/數據類型String char *hamming = NULL;
1. List item
在C中無效。
String char *
對我來說不合適。 你可能並不想在那里包含String
。
刪除第9行的“字符串”。
並改變這一行:
for(i = 1, i < hamlength; i = i * 2){
對此
for(i = 1; i < hamlength; i = i * 2){
我假設你的代碼“1.列表項目”並不是真的存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.