Terminality icon indicating copy to clipboard operation
Terminality copied to clipboard

Terminality does not handle "scanf" inputs correctly in C

Open monotykamary opened this issue 9 years ago • 5 comments

printf works:

#include <stdio.h>

int main() {
    printf("Insert an integer: ");
}

printf

printf + scanf doesn't work so well and printf only appears after an input:

#include <stdio.h>

int main() {
    int n;
    printf("Insert an integer: ");
    scanf("%d", &n);
}

printf + scanf

but the inputs before the print are added to the calculation:

#include <stdio.h>

int main() {
    int n;
    printf("Insert an integer: ");
    scanf("%d", &n);
    printf("n + 3 = %d", n + 3);
}

printf + scanf + calculation proof

Outside of terminality, it works perfectly fine in CMD and Git Bash. Terminality has no problems running Python.

Currently running Windows 10 x64 with Sublime 3083.

monotykamary avatar Sep 29 '15 15:09 monotykamary

The problem is Terminality shell is not a terminal emulator which cause the output to be buffered which is why you have to enter all inputs before it printing out the result.

To solve this issue, you might want to flush the output after printing so Terminality can pick up the output from the buffer.

spywhere avatar Sep 29 '15 15:09 spywhere

I will mark this issue as enhancement instead of bug since I also want the Terminality to print out the output without flush the buffer.

spywhere avatar Sep 29 '15 15:09 spywhere

Oh, so that's how it works. Many thanks and sincere appreciation and sorry for the trouble!

monotykamary avatar Sep 29 '15 16:09 monotykamary

No problem! Issue like this always help improve quality of the plugin :)

spywhere avatar Sep 29 '15 16:09 spywhere

but if i use cin cout it can output without bufferring

khokho avatar Dec 28 '15 14:12 khokho