I need to read all N numbers in a line in an array where N is unknown. When a newline is encountered, read the next X numbers in another array. X is also unknown.
The input is in the format:-
1 2 3 4 5 .. to N (store in array A)
1 2 3 4 .. to X (store in array B).
How to take the input for this case?
you can try
while ( scanf(" %d%c", &num, &ch) == 2 )
{
if ( ch =='\n') break;
// to do :: store or whatever you want
}
it read untill get newline.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.