синтаксис и ошибка разбора - PullRequest
0 голосов
/ 17 марта 2011

Я получаю синтаксическую ошибку в строке 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;
   }

Ответы [ 4 ]

2 голосов
/ 17 марта 2011
#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)

Заменить , на ;


In main() функция

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

Когда пользователь введет свой выбор?

0 голосов
/ 17 марта 2011

Удалить строку «Строка» в строке 9.

И измените эту строку:

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

К этому

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

Я предполагаю, что в вашем коде "1. Элемент списка" на самом деле не существует.

0 голосов
/ 17 марта 2011

String char * мне не подходит. Вы, вероятно, не хотели включать туда String.

0 голосов
/ 17 марта 2011
#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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...