Im unsure how to read all the lines of a file, atm it only reads the first line of the code in the text file. Can someone show me how to make it read all the lines?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *fp;
fp = fopen("specification.txt", "r");
char ** listofdetails;
listofdetails = malloc(sizeof(char*)*6);
listofdetails[0] = malloc(sizeof(char)*100);
fgets(listofdetails[0], 100, fp);
/*strcpy(listofdetails[0], "cars");*/
printf("%s \n", listofdetails[0]);
free(listofdetails[0]);
free(listofdetails);
fclose(fp);
return 0;
}
MY text file:
10X16 de4 dw9 ds8 g8,7 m3,4 h6,5 p2,2
10X16 de4 dw9 ds8 g8,7 m3,4 h6,5 p2,2
10X16 de4 dw9 ds8 g8,7 m3,4 h6,5 p2,2