0

I'm studying C language , so i'm new to C . I studied in High School just Pascal . I have an problem :

I have to sort alphabeticaly a bunch of strings that are read from the keyboard until the word "over" it's introduced .

I got an error : incompatible error :

incompatible types when assigning to type ‘char[10]’ from type ‘char’

The code is :

    char *word = (char *)malloc(30);
    int i = 0 ;
    char matrixs[20][10];
    if(word == NULL)
    {
        exit(-1);
    }

do
{
    printf("Insert the word ");
    scanf("%s",word);
    if(strcmp(word,"over") != 0)
    {
        matrixs[i] = *word;
    }

}
while(strcmp(word,"over") != 0);

free(word);
Călin Calin
  • 155
  • 2
  • 10
  • Don't cast the result of `malloc` & friends in C! – too honest for this site Nov 23 '15 at 22:04
  • Duplicate: http://stackoverflow.com/questions/19857043/incompatible-types-when-assigning-to-type-char-from-type-int, http://stackoverflow.com/questions/27707689/error-incompatible-types-when-assigning-to-type-char25-from-type-char, http://stackoverflow.com/questions/17463487/incompatible-types-when-assigning-to-type-char128-from-type-char. – R Sahu Nov 23 '15 at 22:14
  • Do not use do/while, this construction is legal but tends to induce bugs or redundant tests. In your case, use a `for (;;)` loop and break from it this way: `if (!strcmp(word, "over")) break;`. It would be wise to also break from the loop upon end of file by testing: `if (scanf("%29s", word) == EOF) break;` – chqrlie Nov 23 '15 at 22:16
  • I replaced ' matrix[ i ] = word; ' with ' strcpy(matrix[ i ] , word) ' and it works . In future i will use ' for() ' instead of ' do ' . – Călin Calin Nov 23 '15 at 22:23

0 Answers0