syntax and parse error
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 (开发者_JAVA技巧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<>
You meant
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
?
String char *hamming = NULL;
What is String
doing here? It is not a C keyword. Remove String
from that line.
Your code is full of syntax and logic errors.
1. List item // should be commented
errorBit += ((currenttBit ^(hamming[hamlength - i] - '0')) + i);
Typo here currenttBit
should be currentBit
for(i = 1, i < hamlength; i = i * 2)
Replace ,
with ;
In main()
function
int choice=0;
while(choice!=3)
When would the user enter his choice?
String char *
doesn't look right to me. You probably didn't mean to include String
there.
Remove the "String" on line 9.
And change this line:
for(i = 1, i < hamlength; i = i * 2){
To this
for(i = 1; i < hamlength; i = i * 2){
I'm assuming that in your code "1. List item" isn't really there.
#include<stdio.h> // this is the right way to include header files
#include<stdlib.h>
#include<math.h>
String
is not valid keyword/datatype of C in String char *hamming = NULL;
1. List item
is not valid in C.
精彩评论