引号的都是字符呀!
'0400'哪有这么大的字符!
直接写成
a=040
b=0x40
c=0400
我的例程展示了如何不回车读一个字符。其实就是模拟经常看到的让用户输入 Y or N 的小程序。#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main()
{
char ch
struct termios old_term
struct termios cur_term
int ret
tcgetattr(STDIN_FILENO, &old_term)
memcpy(&cur_term, &old_term, sizeof(cur_term))
cur_term.c_lflag &= ~(ICANON)
cur_term.c_cc[VMIN] = 1
cur_term.c_cc[VTIME] = 0
ret = tcsetattr(STDIN_FILENO, TCSANOW, &cur_term)
if (ret <0)
{
printf("Can't set\n")
return 1
}
printf("Are you OK? [Y/n] ")
fflush(stdout)
ret = read(STDIN_FILENO, &ch, 1)
if (ret <= 0)
{
printf("Error\n")
}
else
{
if (ch == 'y' || ch == 'Y')
{
printf("\nYour choice is YES\n")
}
else if (ch == '\n')
{
printf("You make no choice, default to YES\n")
}
else if (ch == 'n' || ch == 'N')
{
printf("\nYour choice is NO\n")
}
else
{
printf("\nInvalid choice\n")
}
}
tcsetattr(STDIN_FILENO, TCSANOW, &old_term)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)