I need to get integers from a string that an user enters into the console.
For exemple:
I have this string: [1, 2, 3, 4, 5]
and I would like to get all of the integers from it. I already tried multiple scanf
patterns, such as scanf("%*[^\[]%d,", &a)
, but nothing worked. I couldn't find anything relevant on Stack Overflow either.
The main problem is that he can enters between 1 and 50 integers into his string. I have no idea about how to stock only integers (removing ',' and '[' ']' ) into an array.
Some solutions have been found for removing special chars such as [ ] or , But now I still need to remove SPACE between comas and integers...
EDIT : problem solved using fgets. I was using scanf to get my string, but it were stopping to SPACES.
Fond out how to do that with scanf :
while(scanf(" %d",&i))