2011-03-17 119 views
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; 
    } 
+0

'1。列表項無效C.可能是剪切粘貼錯誤,但這是「明顯」的問題。您還應該指出上述代碼中的哪些行是31/32/33/38行。 – 2011-03-17 04:30:58

回答

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

String無效關鍵字/ C的String char *hamming = NULL;數據類型

1. List item無效在C.

2
#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 < hamlength; i = i * 2)

更換,;


main()功能

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

當將用戶輸入他的選擇?

0

String char *看起來不正確。你可能並不是想在那裏包括String

0

上線9

刪除 「字符串」,改變這一行:

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

對此

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

我假設在你的代碼「1.列出項目「不是真的在那裏。

+0

謝謝大家。修復它。 – Garrett 2011-03-17 05:43:39