奇怪的问题啊

haolly 2013-10-27 11:11:32
#include <stdio.h>
#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
struct flaginfo
{
int fl_value;
char* fl_name;
};
struct flaginfo local_flags[]=
{
ISIG, "Enble signal",
ICANON, "Cannonical input (erase and kill)",
ECHO, "Enable echo";
ECHOE, "Echo ERASE as BS-SPACE-BS",
ECHOK, "Echo KILL by starting new line",
0, NULL
};
struct flaginfo inputflags[]=
{
IGNBRK, "Ignore break condition",
BRKINT, "Signal interrupt on break",
IGNPAR, "Ignore chars with parity erros",
PARMRK, "Mark parity errors",
INPCK, "Enable input parity check",
ISTRIP, "Strip character",
INLCR, "Map NL to CR on input",
IGNCR, "Ignore CR",
ICRNL, "Map CR to NL on input",
IXON, "Enable start/stop output control",
IXOFF, "Enable start/stop input control",
0, NULL

};
void showbaud(int thespeed);
void show_flagset(int thevalue, struct flaginfo thebitnames[]);
void show_some_flag(struct termios* ttyp);
int main()
{
struct termios ttyinfo;
if(tcgetattr(0, &ttyinfo)==-1)
{
perror("cann't not get params about stdin");
exit(1);
}
showbaud((int)cfgetospeed(&ttyinfo));
printf("The erase character is ascii %d, Ctrl-%c\n",
ttyinfo.c_cc[VERASE], ttyinfo.c_cc[VERASE]-1+'A');
printf("The line kill character is ascii %d, Ctrl-%c\n",
ttyinfo.c_cc[VKILL], ttyinfo.c_cc[VKILL]-1+'A');
show_some_flag(&ttyinfo);
}
void showbaud(int thespeed)
{
printf("The baud rate is");
switch(thespeed)
{
case B300:
printf("300\n");break;
case B600:
printf("600\n");break;
case B1200:
printf("1200\n");break;
case B1800:
printf("1800\n");break;
case B2400:
printf("2400\n");break;
case B4800:
printf("4800\n");break;
case B9600:
printf("9600\n");break;
default:
printf("Fast\n");break;
}
}



void show_some_flag(struct termios* ttyp)
{
show_flagset(ttyp->c_iflag, input_flags);
show_flagset(ttyp->c_lflag, local_flags);
}
void show_flagset(int thevalue, struct flaginfo thebitnames[])
{
int i;
for(i=0;thebitnames[i].fl_value;i++)
{
printf("%s is", thebitnames[i].fl_name);
if(thevalue & thebitnames[i].fl_value)
printf("ON\n");
else
printf("OFF\n");
}
}


gcc编译输出:
showtty.c:12:5: warning: missing braces around initializer [-Wmissing-braces]
showtty.c:12:5: warning: (near initialization for ‘local_flags[0]’) [-Wmissing-braces]
showtty.c:14:24: error: expected ‘}’ before ‘;’ token
showtty.c:21:5: warning: missing braces around initializer [-Wmissing-braces]
showtty.c:21:5: warning: (near initialization for ‘inputflags[0]’) [-Wmissing-


...全文
161 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
haolly 2013-10-28
  • 打赏
  • 举报
回复
引用 3 楼 worldy 的回复:
#include <stdio.h> #include <termios.h> #include <stdlib.h> #include <unistd.h> struct flaginfo { int fl_value; char* fl_name; }; struct flaginfo local_flags[]= { {ISIG, "Enble signal"},//每个数据单元必须使用大括号 {ICANON, "Cannonical input (erase and kill)"}, {ECHO, "Enable echo"}; {ECHOE, "Echo ERASE as BS-SPACE-BS"}, {ECHOK, "Echo KILL by starting new line"}, {0, NULL} }; ....
原来是这问题,那个分号错误不是主要问题
光流溢彩 2013-10-28
  • 打赏
  • 举报
回复

 {ECHO, "Enable echo"};

如果;是你要的内容的话  需要写成  {ECHO, "Enable echo"}\;
yulitingfeng 2013-10-28
  • 打赏
  • 举报
回复
呵 呵。。。
To_be_sky 2013-10-28
  • 打赏
  • 举报
回复
这个应该应该蛮简单的,看错误信息就知道了; showtty.c:14:24: error: expected ‘}’ before ‘;’ token 很明显应该是“,”。
worldy 2013-10-28
  • 打赏
  • 举报
回复
另外, {ECHO, "Enable echo"}; 后面应该是,
worldy 2013-10-28
  • 打赏
  • 举报
回复
#include <stdio.h> #include <termios.h> #include <stdlib.h> #include <unistd.h> struct flaginfo { int fl_value; char* fl_name; }; struct flaginfo local_flags[]= { {ISIG, "Enble signal"},//每个数据单元必须使用大括号 {ICANON, "Cannonical input (erase and kill)"}, {ECHO, "Enable echo"}; {ECHOE, "Echo ERASE as BS-SPACE-BS"}, {ECHOK, "Echo KILL by starting new line"}, {0, NULL} }; ....
booirror 2013-10-27
  • 打赏
  • 举报
回复
这个错误很明显啊 4个警告,1个错误 showtty.c:14:24: error: expected ‘}’ before ‘;’ token 表示14行第24字符有错 你回头看看,这里确实不应该是";"号,而应该是","
liuzihe1979 2013-10-27
  • 打赏
  • 举报
回复
14行最后的;应该改为,号吧

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧