Home > Back-end >  Questions about the scanf C language
Questions about the scanf C language

Time:04-06

Want to ask bosses, is there any way can in the case of don't know the number of input, store the input to the array? For example: from the keyboard input line 2, 3, 5 1 12... (return), the input number is not given, want to use this line of data stored in blank space to separate into an array, how to implement? My idea is to use a character array, '\ n' to end, and then converts the characters inside force to integers, but this method seems to be very complex, is there a simpler way?
I still have a kind of want to idea is to use the
Int I=0;
While (the scanf (" % d ", a [I])!=(EOF)
{
i++;
}, but it can't stop, want to finish with CTRL + z, there are no '\ n' end? Guide for bosses,

CodePudding user response:

Reference:
 # include & lt; Stdio. H> 

Int main ()
{

Int a [100], I=0, j.

While ((the scanf (" % d ", & amp; A [i++])==1) & amp; & ((getchar ())!='\ n'));
//method one: to enter as a terminator, finally enter there can be no Spaces in front of the

//while (the scanf (" % d ", & amp; A [I])==1 & amp; & a[i]!=0) {i++; }
//method 2: to zero or other digital as the terminator, the input end of the

For (j=0; JPrintf (" % d ", a [j]);

return 0;
}
  • Related