get formated input from a text file

Hi,
(not using C++ ... just C)

If i use ...
fscanf(fp, "%d %s %d", &s.numero, s.nome, &s.idade)
...i will get strange results if i try to read a line like ...
1 love this game 2
The problem is in the space character between the words.

Is there a simple solution for this?

Thanks
There's a solution. I don't know if it's simple.
Read one word at a time and check if it can be converted to an integer. If it can, then use the integer value, otherwise append the word to the accumulated string.
fscanf(fp, "%d %[^0-9] %d", %s.numero, s.nome, $s.idade)
Remember, you'll have to strip the extra space off the end of the nome string after reading it.

Hope this helps.
Topic archived. No new replies allowed.