Reading lines from a file and storing it in an array from typdef struct
I'm trying to read in lines for a file and storing it in an array. This is what I have so far. Am I allocating the memory correctly?
Code:
typedef struct {
/* declartion of variables */
} App
typedef struct {
App* appts[8]; /* an array of 8 pointers to typedef struct App */
char days; /* array that is dynamically allocated of typedef struct June */
} June;
int
main()
{
if (argc != 3)
exit;
else
{
FILE *fp = fopen( argv[1], "r");
char line[150];
int i;
June *days;
fgets(line, 150, fp);
while(fgets(line, 100, fp) != NULL) /* reading lines from a file */
{
days[i] = (char *)malloc(sizeof(char)); /* storing it in an array using malloc to allocate memory */
strcpy(days[i], line);
i++;
}
fclose(fp);
}
}
Questions that I have:
How do I access the array content? I'm suppose to strtok the contents from the lines stored in the array and use it again.
Any help is appreciated. Thanks