vendredi 30 octobre 2015

Reading from file into array, line by line

I am trying to read from a file in C. My code is the following. It seems to read everything fine into the array, but when I try to print it, I get the error Segmentation fault (core dumped)

  FILE *fp;
   char * text[7][100];
   int i=0;

   fp = fopen("userList.txt", "r");

   //Read over file contents until either EOF is reached or maximum characters is read and store in character array
   while(fgets((*text)[i++],100,fp) != NULL) ;

   printf("%s", &text[0]);

   fclose(fp);

Can someone point me in the right direction?

I have tried reading and copying solutions from other similar cases, but they are extremely specific to the user.

Aucun commentaire:

Enregistrer un commentaire