Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the range of number is varies
ex;
at first input user enter 1 2 3 4 5 6 7

at second input 1 2 3 4 5 6 7 8 9 63 44 32 12 etc


the problem is that i want to read all integer in a single scanf statement in c please help
Posted
Comments
Vedat Ozan Oner 7-Mar-14 7:11am    
google it first.

1 solution

You can't read a variable number of input values in a single scanf statement - if you don't know the number of numbers the user will enter, then you need to:
1) Read the whole line, using fgets
2) Convert it to separate inputs using strtok
3) Process each input using sscanf

While you can say:
C++
scanf("%d %d %d", &a, &b, &c);
There is no mechanism for variable numbers of inputs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900