search

Home  >  Q&A  >  body text

dev-c++编译后一闪而过。

dev-c++编译后一闪而过。加了system("pause");或者getchar();也一样。。

#include<stdio.h>
main()
{
    int a,b,c; 
    scanf("%d %d",&a,&b);
    c=a+b;
    printf("%d",c);
    system("pause");
    return 0;
} 
迷茫迷茫2819 days ago620

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:41:37

    You need to import system("pause"); to use stdlib.h. If it still doesn’t work, it is unreasonable and may have something to do with your machine environment

    When using scanf after getchar(), you need to clear the input buffer first, because when scanf is entered and the carriage return is entered, scanf is triggered to receive the previous data, but the 回车 character is still in the input buffer, getchar()This character will be obtained directly, so the window cannot be blocked from closing

    The solution is

    1. First fflush(stdin) (refresh the input buffer), then getchar()
    2. Twicegetchar(), the first time will swallow the previous 回车, and the second time will block the program execution, waiting for input

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:41:37

    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
        int a,b,c; 
        scanf("%d %d",&a,&b);
        c=a+b;
        printf("%d",c);
        system("pause");
        return 0;
    } 
    

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:41:37

    Add the last line system("pause"); to include the header file #include <stdlib.h>

    reply
    0
  • Cancelreply