Hi all. So I have an assignment where I need to find a specific line in a text file with the word "circles". Using that information I must somehow find how many circles there are. (the text files says how many circles there are before the word circles. eg. "3 circles") Next, I have to skip a certain amount of lines after circles and do the same as above for "friends". However, with friends, I have to read in each line and parse the information and store it in the friends array. Here's my code for now and it is VERY rough right now. Help would be very very nice as I am almost completely lost.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <printFriends.h>
void main(int argc, char **argv)
{
int i,size, wordnum;
char max[256];
char *fname, *word, *friends, *circles;
FILE *file;
//Check for command line arguments
if (argc <= 1)
{
printf("Insufficient number of inputs\n");
exit(1);
}
//Open the file and check if file exists
fname = argv[1];
file = fopen(fname,"r");
if (file == NULL)
{
printf("Cannot open input file %s\n",fname);
exit(2);
}
//Read in file line by line and search word
while(fgets(max, sizeof(max), file) != NULL)
{
size = strlen(max);
circles = strstr(max, "circles");//????
word = strtok(max," \n");
while(word != NULL)
word = strtok(NULL," \n");
}
//Allocate array for number of friends
friends = (char *)malloc(//something);
fclose(file);
}