在具有GDB的Eclipse CDT中,Scanf似乎无法在调试模式下工作 [英] Scanf doesn't appear to work in debug mode in Eclipse CDT with GDB

查看:88
本文介绍了在具有GDB的Eclipse CDT中,Scanf似乎无法在调试模式下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试模式下运行此代码时:

When running this code in debug mode:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("Values entered: %d %d %d\n", a, b, c);
    return EXIT_SUCCESS;
}

该程序不会请求任何用户输入,只会输出:

The program would not request any user input and would just output:


输入的值:18 78 2130026496

Values entered: 18 78 2130026496


推荐答案

我遇到了同样的问题。弄清楚如果使用换行符或使用输入功能,则必须清除输出缓冲区。因此,请按照这种方式执行。

I had the same problem. Figured out that you have to clear output buffer if a newline character is used or if an input function is used. So, do this way..

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c;
    fflush(stdout);//Clears the stdout buffer
    scanf("%d%d%d", &a, &b, &c);
    printf("Values entered: %d %d %d\n", a, b, c);
    return EXIT_SUCCESS;
}

这篇关于在具有GDB的Eclipse CDT中,Scanf似乎无法在调试模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆