compare char in matrix

hi,

i got the next error:
argument of type "char" is incompatible with parameter of type "const char *"

the error is about the next row:

if(strcmp(matrix[i+1][j] , matrix[i][j]) == 0 )

the Definition of matrix:

char matrix[10][5]={{'h','o','u','s','e'}, {'a','p','p','l','e'}, {'t','e','a','c','h'}, {'a','r','r','a','y'}, {'t','a','b','l','e'}, {'b','o','o','k','s'} , {'p','o','i','n','t'}, {'f','l','o','a','t'}, {'a','p','p','l','y'}, {'b','e','g','i','n'}};

what can i do??

thanks to all
strcmp is a function for comparing strings of characters and you only give it single chars. If you want to compare the two chars, just use operator ==. If you want to compare substrings that start at specified positions, write matrix[i]+j or &matrix[i][j]. Although your strings wouldn't be null terminated.. You could get away with strncmp.
Last edited on
@hamsterman: Can you explain it a little bit more in detail? I still cant understand it clearly. Please?
Basically @hamsterman said that since your matrix contains chars you can use a comparison like:
if(matrix[i+1][j] == matrix[i][j]) that will work as expected.

If you want to compare substring (that is a series of char not just 1) strcmp() takes as argument a const char * so use matrix[i]+j or &matrix[i][j].
if(strcmp(&matrix[i+1][j] , &matrix[i][j]) == 0 )
This requires not to contain \0 in inappropriate place (like inside a string and not in the end) and requires a \0 at the end (as C string work).

strncmp() works as strcmp but takes a 3rd argument if you want to declare the actual number of chars to be tested.

Is it more clear now?
Topic archived. No new replies allowed.