3

我正在使用以下程序将文本写入文件。

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int ch;
    FILE *fp;
    fp = fopen("myfile.txt", "w");

    if(fp == NULL)
    {
        printf("Error opening file\n");
        exit(1);
    }

    printf("Press Ctrl+D to stop \n\n");

    printf("Enter text: ");

    while( (ch=getchar()) != EOF )
    {
        fputc(ch, fp);
    }

    fclose(fp);

}

假设输入是:

Press Ctrl+D to stop \n\n

Enter text: this is a test
^Z

我的问题是文件结尾字符(ASCII 值 26)是否会写入文件?

4

1 回答 1

0

我验证在 Windows 中使用十六进制编辑器^Z字符未写入文件。

于 2016-09-26T06:44:19.063 回答