I have a problem for 2 days now I haven't been able to exactly figure out. I have a txt file that his a list of stuff divided by semicolons (; character) and at the end it has a newline character for the next list, just like so:
As you can see it is random how many items we get in each line and what I want to do is to put each item in a linked list according to its line in an array. It has to look like so:
I've made the fgets loop and all works it reads each line etc, but I'm stuck to the internal loop required in order to read each item separately inside the line given by fgets. Since it is random how many items we have in each line I can't put the strtok a predetermined amount of times inside the fgets loop and I still can't figure out what to do in order to condition the internal loop to understand that it has to exit after it finds the newline character (since this is our queue to go to the next line). Let me remind you that through strtok you can cut the whole string off according to the tokens but that does not mean that the last characters of the string array are the same as what you see after a printf("%s"). There are many junk characters thus I cannot check if the last char is a newline character...
basic_istream& getline (char_type* s, streamsize n, char_type delim );
delim
The delimiting character. The operation of extracting successive characters is stopped when this character is read. This parameter is optional, if not specified the function considers '\n' (a newline character) to be the delimiting character.