C版 :
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
int main(int argc,char **argv) {
FILE *input = fopen("in.test.txt","r");
char c = '\0';
while (! feof(input)) {
fscanf(input,"%c",&c);
printf("%c",tolower(c));
}
printf("\b\n");
return 0;
}
/*
* in.test.txt: "XXX"
* OutPut: "xxxx"
*/
C++版 :
#include <cstdio>
#include <cerrno>
#include <cctype>
using namespace std;
int main(int argc,char **argv) {
FILE *input = fopen("in.test.txt","r");
char c = '\0';
while (! feof(input)) {
fscanf(input,"%c",&c);
printf("%c",tolower(c));
}
printf("\b\n");
return 0;
}
/*
* in.test.txt: "XXX"
* OutPut: "xxxx"
*/
求助大佬们为什么会最后一个字符输出两次?