代码之家  ›  专栏  ›  技术社区  ›  Cody

^是否将Z字符写入文件?[副本]

  •  3
  • Cody  · 技术社区  · 9 年前

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

    #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)是否会写入文件?

    1 回复  |  直到 9 年前
        1
  •  0
  •   Cody    9 年前

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