I'm not used at all to the fact that strings aren't supported in C like they are in other languages. I have a 2 dimensionnal array with words and I want to return one of the array's word and it doesn't work. I have compiler errors like "return makes integer from pointer without a cast" and "function returns address of local variable" so my guess is that it's returning the addess of the local variable :P
What confuses me is that I can print the word but not return it. I know this could be done with a pointer but I'm wondering if it's possible to do it without.
Code:
#include <stdio.h>
#include <string.h>
char getWord() {
char a_words[5][20];
strcpy (a_words[0],"nucleaire");
strcpy (a_words[1],"patate");
strcpy (a_words[2],"verre d'eau");
strcpy (a_words[3],"table");
strcpy (a_words[4],"compagnon");
printf("%s", a_words[2]);
return a_words[2];
}
int main() {
char word[20];
strcpy(word ,getWord());
printf("%s", word);
return 0;
}
thanks