Reputation: 13
void coordinateInput(int in){
int * input = (int *)malloc(in*(sizeof(int)));
for (int i = 0; i < in; i++){
printf("Please enter the x coordinate for control point #%d: ", i);
scanf("%d\n",&input[i]);
printf("Please enter the y coordinate for control point #%d: ", i);
scanf("%d\n",&input[i+1]);
}
}
In output you can see after line 0 it asks for another input:
I want the to get only one input but I end up having the input twice for some reason. Its only true for first case only.
Upvotes: 1
Views: 39
Reputation: 46
I fixed it removing '\n' from the scanf statement and adding it in the printf.
int * input = (int *)malloc(in*(sizeof(int)));
for (int i = 0; i < in; i++){
printf("Please enter the x coordinate for control point #%d: ", i);
scanf("%d",&input[i]);
printf("\nPlease enter the y coordinate for control point #%d: ", i);
scanf("%d",&input[i+1]);
//[In output you can see after line 0 it asks for another input][1]}
printf("%d - %d\n", input[i], input[i+1]);
}
The code should be something like that.
Upvotes: 1