Compiler Error in C -- Expected ')' before '!' token. -
i'm coding basic program check if string palindrome or not.
#include <stdio.h> #include <string.h> //has useful functions strings. #include <ctype.h> //can sort between alphanumeric, punctuation, etc. int main(void) { char a[100]; char b[100]; //two strings, each 100 characters. int firstchar; int midchar; int lastchar; int length = 0; int counter = 0; printf(" enter phrase or word palindrome checking: \n \n "); while ((a[length] == getchar()) !10 ) //scanning input ends if user presses enter. { if ((a[length -1]), isalpha) // if character isalpha, keep it. { b[counter] = a[length-1]; counter++; } length--; //decrement. } makelower(b, counter); //calls function changes uppercase lowercase. for( firstchar = 0; firstchar < midchar; firstchar++ ) //compares first , last characters. { if ( a[firstchar] != a[lastchar] ) { printf(", not palindrome. \n \n"); break; } lastchar--; } if( firstchar == midchar ) { printf(", palindrome. \n \n"); } return 0; } //declaring additional function "makelower" change remaining lowercase chars. int makelower (char c[100], int minicount) { int count = 0; while (count <= minicount) { c[count] = tolower(c[count]); } return 0; }
and i'm getting following compiler error on line first while loop, after printf statement:
p5.c: in function 'main': p5.c:30: error: expected ')' before '!' token
i've looked , down, haven't found out-of-place or nonpartnered parenthesis. thing can think of i'm missing comma or kind of punctuation, i've tried placing comma in few places no avail.
sorry if specific. in advance.
while ((a[length] == getchar()) !10 )
what looks you're trying assigning a[length]
result of getchar()
, verifying that not equal 10
. spelled so:
while ((a[length] = getchar()) != 10)
=
assignment, ==
test.
further, counters confused. length
initialized 0
, decremented, lead falling off front of array after first decrement. doesn't chance happen, because attempt access a[length-1]
, fail. looks off-by-one error, known fencepost error, in accessing character read getchar().
also, since nothing checking length of recorded input doesn't exceed length of buffer a[100]
, fall off end there well.
the counters palindrome check function off. midchar
, lastchar
never initialized, midchar
never set, , lastchar
decremented without ever having value set. better off testing a[firstchar] == a[(counter-1)-firstchar]
.
Comments
Post a Comment