I'm still fairly new to C programming and I've been trying to create a program which needs user input first. In the beginning, I need the user to input certain amount of numbers such as: 4 12 8 6 5 4 7
So basically, he keeps on entering numbers, making spaces in between them. The user then presses enter and that is the end of user input. Reading up on the stuff I've already found online, I've seen this posted:
while (...){
scanf("%c",&c[i]);
if(c[i]=='\n')
break;
}
So, now, using the dynamic memory allocation, is it possible to let the user enter everything in one line like this, separated by spaces, then ending it once he presses enter?
What I want to happen:
- user input: 5 4 5 6 8 5 enter
- array = {5, 4, 5, 6, 8, 5}