我试图从input.txt文件中复制文本,但是程序认为空格是新行。我该怎么做?
我的输入. txt (试用版)
1. hero
2. angelic
3. hello world
4. demons
我的来源. c
int main(void) {
FILE* fread = fopen("C:\\Users\\EXAMPLE\\desktop\\input.txt", "r");
if (fread == NULL) {
printf("One file wouldn't open!\n");
return -1;
}
//this pastes the text from input.txt into the command-line
char line[1000] = "";
while (fscanf(fread, "%s", line) == 1) {
printf("%s\n", line);
}
fclose(fread);
fclose(fwrite);
输出
1.
hero
2.
angelic
3.
hello
world
4.
demons
1条答案
按热度按时间s8vozzvw1#
这是你要做的。已经有函数实现来帮助你做这件事。