gnu readline() 从 stdin 读取时出现 gcc 编译错误
大家好,
我参考了互联网上的各种文档,用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试编译
gcc ioprogram.c -o ioprogram -lreadline -lncurses
try compiling with
gcc ioprogram.c -o ioprogram -lreadline -lncurses