I want to create an array with malloc and then assign the fields of the array an output of fgets. ? Then hopefully you should declare words
as double pointer or array of char pointer.
One way is, by using array of char pointer like below.
char *words[lines]; /* array of pointer, lines is nothing but number of line in file */
for(int row = 0;row < lines; row++) {
/* allocate memory for each line */
words[row] = malloc(mysize);/* mysize is nothing but lines has max no of char i.e max no of char */
/* now read from file */
fgets(word[row],mysize,fp);/* reading from file(fp) & store into word[0],word[1] etc */
}
Or you can use double pointer like char **words;
also.
And once job is done, at last don't forget to free the dynamically allocated memory.