gpt4 book ai didi

c - ^Z 字符是否写入文件?

转载 作者:可可西里 更新时间:2023-11-01 09:36:45 25 4
gpt4 key购买 nike

<分区>

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com