Error in the I/O operation
已回答
Hi,
I run this code:
fprintf(stdout, "\n--- The program acquires data ---\nInsert the dimension of the vector: ");
fscanf(stdin, "%d", &i);
assert(i <= 30);
(*v).length = i;
(*v).v = (int *) malloc((*v).length * sizeof(int));
assert((*v).v != NULL);
fprintf(stdout, "Insert the element of the vector:\n");
for (i = 0; i < (*v).length; i++) {
fprintf(stdout, "\t%d element: ", i + 1);
fscanf(stdin, "%d", &(*v).v[i]);
}
and the output is:
4
9
8
7
6
--- The program acquires data ---
Insert the dimension of the vector: Insert the element of the vector:
1 element: 2 element: 3 element: 4 element:
while the correct output must be:
--- The program acquires data ---
Insert the dimension of the vector: 4
Insert the element of the vector:
1 element: 9
2 element: 8
3 element: 7
4 element: 6
Anyone could help me ?
请先登录再写评论。
Hi, Giulio!
Are you on Windows? Do you use MinGW as a toolchain in CLion?
Please try disabling PTY: go to Help | Find Action, type "Registry...", select it and in the opened list find and disable the run.processes.with.pty option. Does it help?
Hi, Anna!
I have already done those instruction. This situation is a conseguence of those instruction.
Please answer the following questions:
1. Yes
2. Yes
3.
4.
If it's possible, please use Cygwin instead of MinGW. In this case the output in CLion will be ok if run.processes.with.pty is enabled.
In case of MinGW you can either
1) enable run.processes.with.pty and endure the "double output" problem,
or
2) disable run.processes.with.pty and add fflush(stdout); after each fprintf line.
And please follow https://youtrack.jetbrains.com/issue/CPP-2580 in order to get updates.