Doubt in C Language

Hello guys,

I have to do a project for college in C in which i have to read an input of about 130k lines.

The lines are of this type:

"John F. Kennedy, George Washington, Thomas Jefferson, 1809

James Madison, James Monroe, John Quincy Adams, Andrew Jackson, 1829

Martin Van Buren, William Henry Harrison, 1841"

 

What I'm using is this:

int write (struct Node *node) {

     char line[1024], author[1024];
     char *token, *comma = ",";
     FILE *p;

     p = fopen ("test.txt", "r");

     while (fgets (line, 1024, p) != NULL) {
          token = strtok (linha, comma);
          strcpy (author, token);
          insert (&node, author);
          memset (author, 0, sizeof (author));
     }

     showTree (node);
     fclose (p);

}

 

and i know this only saves on the tree the first of each line, what i can't seem to figure out is how to to that for the rest of the lines, any thoughts on this?

 

P.S: Sorry for shit editing

A couple of things.  You are assuming that each line of data will be a maximum of 1023 bytes.  What happens if a line is 2000 bytes?  Unless your professor has explicitly said it is OK to assume no line of data is more than 1023 bytes, you will have to read each line dynamically.

Unless reading each line of the file dynamically is part of the assignment, you can use getline(), here's an example:

http://linuxmanpages.com/man3/getline.3.php

For your main question, remember strtok returns the first token contained in the line.  To get the rest of the tokens you have to loop through, asking strtok for the next token.  Here's an example for how to use strtok:

http://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm

It looks like you are planning to use a binary tree to store each author listed on a given line.  Do you plan to store all lines within another binary tree?  Which means you will end up with one binary tree that contains all of the lines of the file, and each line will contain a binary tree containing all of the authors.  Just make sure you realize what you will need.

Sorry if this is a stupid answer, I'll admit I haven't read the full question, but couldn't a bit of this be achieved with regular expressions?