0
切换
我想前面加上数字来了“的putchar”部分,但因为getchar函数是在同一时间抓住一个字符,输出为“喜”变成1 h 2 i
的getchar,在C
int linecount = 1;
int numberflag = 1;
while (1){
int input = getchar(); // use int to make sure var input is big enough to hold EOF plus any other char
switch (input) {
case EOF:
exit(-1);
default:
if (numberflag){
printf("\t%d\t", linecount);
linecount++;
}
putchar(input);
break;
}
}
所有帮助将不胜感激。我试图使输出:
1 hi
2 hello
,而不是
hi 1
hello 2
您需要设置'n umberflag'取决于你得到的'char'。 –
什么是数字标记,它来自哪里? – Lundin
case'\ n':linecount ++ – BLUEPIXY