My advice, go for fgets()
.
- Read the whole
line
from the input - Tokenize using space [
] [or your preferred delimiter] [using
strtok()
] - Allocate memory to store the integer
- Convert the string input to integer [maybe
strtol()
] and store each integer.
Optionally, you may want to add some validation and error checking.
Read more about fgets()
here.
also, don’t forget to get rid of the trailing \n
stored in the read buffer by fgets()