我确信这个问题有一个非常简单的答案。不过,我试图在C的开始和结尾添加一个字符。我在开始部分添加了一些字符,但是在添加到结尾部分时遇到问题。有没有简单的解决方案,只是使用我的代码?在此先感谢将字符添加到行尾C
#include <stdio.h>
int main(void) {
char c; // store a character
printf("0");
while (scanf("%c", &c) != EOF) {
printf("%c", c);
if (c == '\n') {
printf("0");
} // if
} // while
return 0;
} // main
你预计会发生什么,实际发生了什么?如果问题在于你得到一行很长的输出,那么在'if'的右括号之前加上'printf(“\ n”);'。 – 2012-02-01 03:43:12