2
I am very beginner in C yet, but I have a lot of experience with python, I have a project that I need to receive from the user 3 numbers in the same line and make a vector with these 3 numbers
in the input digit
3 1 37
wanted it to form a vector [3,1,37] only one thing, the first (in this case the 3) can also be characters. something like
load 1 23 or delete 2 56
in python would be extremely simple, just received a string input and dps do an input=split.()
#include <stdio.h>
#include <string.h>C
int main ()
{
char entrada[31];
char * separado;
gets(entrada);
separado = strtok (entrada," ");
while (separado != NULL)
{
printf ("%s\n",separado);
separado = strtok (NULL, " ");
}
return 0;
}
I found this code in a gringo forum, someone knows if there is a simpler way or so explain to me how it works? I do not understand
Pertinent to your question, however you do not want split (split verb in English that means divide, separate) Oce needs concatenate data, that is, join 3 data passed by the user separated by comma in an array.
– gfleck
but it would be like splitting 1 string into 3
– Levy Barbosa
I understood, but where will the user pass these numbers, what is the origin of these 3 numbers? It comes direct from the terminal? If there are 3 numbers (3 distinct data) it is necessary a certain separator?
– gfleck