[Solved] input data in one line separated by white spaces in C? [closed]


There are many possible solutions that I can think of.

The various solutions are:

  1. Reading the input character by character and then upon spaces, creating words out of it.
  2. Using a va_list (variable argument list).
  3. 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]