It is necessary to read only one line with a set of integers separated by space, each item separated by space will be inserted in a linked list: 1 41 2 15 6 7 87 4 2 1 9 0
List would be something like = [1, 41, 2, 15, 6, 7, 87, 4, 2, 1, 9, 0]
Example:
$ gcc example.c -o example -g -Wall
$ ./example
1 41 2 15 6 7 87 4 2 1 9 0<enter>
The biggest problem is that the number of numbers that will come into the input is undefined, that is, the input can also be: 1 8 6
Lista = [1, 8, 6]
Because the quantity is undefined, I thought of two possible solutions:
- a)
scanf ("%[^\n]%*c", sequenciaNumeros);
- b) Use
fgets
In both cases, I would have the problem of declaring a huge array of characters to ensure that it does not reach the limit.
If the quantity was defined it would be simple:
scanf("%d %d %d, &valor1, &valor2, &valor3)
Is it possible with scanf
to pick up this line and be able to manipulate each of the numbers (which are separated by space) to add to the list, knowing that the number of numbers can vary ? The entry is mandatory only one row of a set of numbers separated by space