C - how to get fscanf() to determine whether what it read is only digits, and no characters

Posted by hatorade on Stack Overflow See other posts from Stack Overflow or by hatorade
Published on 2010-04-11T03:33:02Z Indexed on 2010/04/11 3:43 UTC
Read the original article Hit count: 325

Filed under:
|
|

Imagine I have a csv with and each value is an integer. so the first value is the INTEGER 100.

I want fscanf() to read this line, and either tell me it's an integer ONLY, or not. So, it would pass 100 but fail on 100t. What i've been trying to get work is "%d," where the comma is the delimiter of my CSV. so the whole function is

fscanf(fp, "%d,", &count)

Unfortunately, this fails to fail on '100t,' works on '100' and works on 't'. so it just isn't distinguishing between 100 and 100t (all of these numbers are followed by commas, of course

© Stack Overflow or respective owner

Related posts about c

    Related posts about fscanf