If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Not sure how parse this file correctly

I am very new when it comes to C and C++ as well as the fact that I haven't touched the language in over a year so I am having some trouble trying to figure out the syntax/logic for this particular problem I am having. Here is the fragment of code I am having trouble with:

What I am trying to do is parse through a CSV file and each set of data is seperated by a comma so I figured I could make a while look that will keep inputting the data into the string until it reaches a comma then increment "i" once more. This particular piece of code is just to skip through the file. I am sure this is an easier way to do this but I don't know it. The only real problem is line 19 I don't know how to write it so that the while loop will be looking at the file output.
Thanks for the help

Re: Not sure how parse this file correctly

Originally Posted by LorenzoVonMatterhorn

I am very new when it comes to C and C++ as well as the fact that I haven't touched the language in over a year so I am having some trouble trying to figure out the syntax/logic for this particular problem I am having. Here is the fragment of code I am having trouble with:

What I am trying to do is parse through a CSV file and each set of data is seperated by a comma so I figured I could make a while look that will keep inputting the data into the string until it reaches a comma then increment "i" once more. This particular piece of code is just to skip through the file. I am sure this is an easier way to do this but I don't know it. The only real problem is line 19 I don't know how to write it so that the while loop will be looking at the file output.
Thanks for the help

Perhaps read each line using "fgets" in a while loop, and then interpret it accordingly. If a line has a ",", then break, otherwise do whatever with the line string.

Re: Not sure how parse this file correctly

Originally Posted by LorenzoVonMatterhorn

The original "reader" array is actually char reader[2000]; I accidentally changed it when I was rewriting that to be a much smaller bit of code

Don't rewrite anything into this forum. Rewrite it into a small example project and then compile it. Many times you can resolve problems during that process. If you can't then you can post it within code tags (use the # button above the edit box) and a question.

Re: Not sure how parse this file correctly

I recommend searching the forums for a solution. I'll bet that you will find many questions about processing CSV files. Your initial post doesn't lead me to believe that you put much effort into this on your own.

Re: Not sure how parse this file correctly

I did compile it several times and it did not help at all, however other than line 19 of the code everything else was functioning, I will take some time later tonight to sift through the other threads thank you kempofighter. I have been looking for several days however I have not taken the time to search through this particular particular forum.