Help with reading a file in C, please. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with reading a file in C, please.

veyerveyer Posts: 7Member
I have a file with 190 lines, that goes something like this:

[code]Antigua,English,Local dialects
Costa Rica,Spanish,English
First field is the country, following fields are the different languages spoken in that country.
Since some countries have more languages than others, I am stuck trying to read the file using fgets() and sscanf().
I'm doing this:
while(i < SIZE && fgets(buffer, 255, fp))
sscanf(buffer, "%[^,]%*c%[^
]", holdName, buffer);//read the country first, and keep the rest for the languages

/* Here is where I'm lost, I want to read a language, keep the rest of the buffer to repeat until
the buffer is empty. But obviously I'm doing it wrong */
while(sscanf(buffer, "%[^,]%*c%[^
]", holdLang, buffer) != '

Any help please?
I have this big program to do, and can't do anything else until I am able to read the whole file.



Sign In or Register to comment.