October 26, 2024
Chicago 12, Melborne City, USA
C++

My program takes too long to start when there is an input needed from the user


I’m using Code::Blocks with the GCC compiler to write C programs as a first-year CS student. I encountered a strange issue when using scanf() in my programs.

The program compiles normally, but when I run it, the terminal window opens immediately and takes about 15 seconds to display any messages or input prompts. However, if I stop the program and re-run it without rebuilding, it starts instantly. The issue reappears if I rebuild the program. When I remove the scanf() calls, the program runs without any delay.

I’ve tried different approaches but couldn’t figure out why this happens. Any insights into what might be causing this delay or how to fix it?

Example of a program:

#include <stdio.h>

main() {
    int i, x, n;
    int s = 1;
    printf("entrer x \n");
    scanf("%d", &x);
    printf("entrer n \n");
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        s = s * x;
    }
    printf("%d ^ %d = %ld \n", x, n, s);
}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video