There are many possible solutions that I can think of.
The various solutions are:
- Reading the input character by character and then upon spaces, creating words out of it.
- Using a
va_list
(variable argument list). - Continually scanning numbers until the end of line.
I am showing you how to implement the first one. The rest are for you to try.
while((ch = getchar()) != '\n')
{
if(ch == ' ')
{
a[count++] = atoi(numString);
i = 0;
numString[i] = '\0';
}
numString[i++] = ch;
numString[i] = '\0';
}
a[count++] = atoi(numString);
solved input data in one line separated by white spaces in C? [closed]