I have an array called array, and I want to copy a word that I have read in from some file and store it into that array at a certain index, how can I don it?
I thought when a file is read all input from the file is in "string" form. So if a number 100 is in the file its represented as "100".
I have tried the following:
#define maxlength 10
char array[10];
int i = 0;
char word[maxlength];
strcpy(array[i], word); //error
array[i] = word; //error
My guess is because the word is an array of characters it's not actually a string to copy through. Is there a way I can copy the word[] into the array[] in a string format? I.E. index 0 in array = ["hello"] index 1 = ["world"] etc.
maxlength?helloin one character?strcpy(array, word);?char array[10]declares an array of10-char. When referencing an element of an array[ ]acts as a dereference. So whilearraymay be typechar *(due to C11 Standard - 6.3.2.1(p3)),array[i]is typecharresulting in your attempt tostrcpyfailing due toarray[i]being an incompatible type.