gnu readline() 从 stdin 读取时出现 gcc 编译错误

发布于 2024-10-17 08:05:56 字数 1259 浏览 0 评论 0原文

大家好,

我参考了互联网上的各种文档,用gnu​​ readline库编写了一个小程序,名为“ioprogram.c”。但是,gcc 报告以下错误。我的问题是什么?

#include <readline/readline.h>
#include <stdio.h>
int main()
{
    char* c = readline("");
    int len = strlen(c);
    for(int i=0; i<len; i++)
    {    
        printf("%c", *(c+i));  
        fflush(stdout);        
    }
    free(c);
}

gcc 错误:

In file included from /usr/include/readline/readline.h:37,
                 from ioprogram.c:1:
/usr/include/readline/rltypedefs.h:65: error: expected ‘)’ before ‘*’ token
In file included from ioprogram.c:1:
/usr/include/readline/readline.h:416: error: expected ‘)’ before ‘*’ token
/usr/include/readline/readline.h:532: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:533: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:555: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:823: error: expected specifier-qualifier-list before ‘FILE’
ioprogram.c: In function ‘main’:
ioprogram.c:7: error: ‘for’ loop initial declaration used outside C99 mode

提前感谢您的任何评论。

HI, guys,

I write a small program, named "ioprogram.c", with gnu readline library, refering various documentation on the Internet. however, gcc reports the following errors. what is my problem?

#include <readline/readline.h>
#include <stdio.h>
int main()
{
    char* c = readline("");
    int len = strlen(c);
    for(int i=0; i<len; i++)
    {    
        printf("%c", *(c+i));  
        fflush(stdout);        
    }
    free(c);
}

gcc errors:

In file included from /usr/include/readline/readline.h:37,
                 from ioprogram.c:1:
/usr/include/readline/rltypedefs.h:65: error: expected ‘)’ before ‘*’ token
In file included from ioprogram.c:1:
/usr/include/readline/readline.h:416: error: expected ‘)’ before ‘*’ token
/usr/include/readline/readline.h:532: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:533: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:555: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:823: error: expected specifier-qualifier-list before ‘FILE’
ioprogram.c: In function ‘main’:
ioprogram.c:7: error: ‘for’ loop initial declaration used outside C99 mode

Thanks in advance for any comments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2024-10-24 08:05:56

尝试编译
gcc ioprogram.c -o ioprogram -lreadline -lncurses

try compiling with
gcc ioprogram.c -o ioprogram -lreadline -lncurses

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文