[Solved] C – Input numbers in line splitted by comma [closed]


Why do you want to do this? Just take as input an integer array without commas. But if you want, then here is how to achieve it.
You can use a character array to keep such data. An integer array will not do.
Your input will be stored as:

char a[3];
a[0]='1';
a[1]=',';
a[2]='2';

So to take the input, first define a character array a[n] of size n, then take the input as

while(i<n)
{
    a[i]=getchar();
    i++;
}

This will keep your data in the array as a[n]={'1' , ',' , '2' , ',' upto n}
You can then print them as

i=0;
while(i<n)
{
    putchar(a[i]);
    i++;
}

You give your input as:

1,2,3,4,5

and the output will be:

1,2,3,4,5

The even numbered indexes will contain the numbers and the odd numbered indexes will contain commas.

solved C – Input numbers in line splitted by comma [closed]