c - Using getchar() to take multiple values. -


could somehow use getchar() run through command line until hit '\n'. want scan in values enter such as.

21 23 1 78 54 '\n'. want scan 5 values array. unable scan them in. because of spacing between each value? or there function use ?

thanks in advance

if not bent on using getchar() have straightforward solution using scanf %d conversion specifier:

while (i < array_size && scanf("%d", &a[i]) == 1)     i++ ; 

the %d conversion specifier tells scanf skip on leading whitespace , read next non-digit character. return value number of successful conversions , assignments. since we're reading single integer value, return value should 1 on success.


Comments

Popular posts from this blog

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -