我正在使用以下程序将文本写入文件。
#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)是否会写入文件?
我在Windows中使用十六进制编辑器进行了验证 ^Z 字符未写入文件。
^Z