0
Follow
0
View

File manipulation - Characters that cannot be correctly removed from the output file

duomeiti051 注册会员
2023-02-28 01:20

The following answers are quoted from GPT-3 model, please use them wisely:

#include 
#include 

int main()
{
    FILE *fp;
    fp = fopen("111.txt", "r"); //以只读方式打开文件 

    if (fp == NULL)
    {
        printf("flaut!");
        exit(0);
    }
    
    char c;
    while ((c = fgetc(fp)) != EOF) //从文件中一次读取一个字符,直到遇到文件末尾 
    {
        if (c != '@') //不是输入结束符
            printf("%c", c);
        else
            break;
    }
    
    fclose(fp);
    return 0;
}

Please accept my answer if it answers your question

tarot_lily 注册会员
2023-02-28 01:20

This answer quotes ChatGPT

Modify the code as follows


#include 
#include 

int main() {
    FILE *fp;
    fp = fopen("111.txt", "r+");

    if (fp == NULL) {
        printf("flaut!");
        exit(0);
    }

    char c;
    while ((c = fgetc(fp)) != '@') {
        printf("%c", c);
    }

    fclose(fp);

    return 0;
}


ddl23010 注册会员
2023-02-28 01:20
< div class = "md_content_show e397 data - v - 3967" = "" >

? return

csc1224 注册会员
2023-02-28 01:20

Please see the comments for the changes:

#include
#include
int main()
{
    FILE *fp;
    fp=fopen("111.txt","r+");
    if(fp==NULL)
    {
        printf("flaut!");exit(0);
    }

    char c;
    while((c=fgetc(fp))!='@')  //(c=fgetc(fp)!='@') 修改
    {
        printf("%c",c);    
    }
    fclose(fp);
    return 0;   //修改
}


About the Author

Question Info

Publish Time
2023-02-28 01:20
Update Time
2023-02-28 01:20

Related Question

Xcode 13和Linux Makefile

301 redirect all except robots.txt file

Using Python os.walk or os.path to build an XML file based on subdirectory file contents

传递FILE*作为参数

Dockerfile运行屏幕命令,同时保持它的连接

使用dockerfile部署Golang程序报错

在Qt readFile中使用libconfig失败

在Dockerfile中带有管道的CMD不能转发

来自守护进程的错误响应:dockerfile解析错误行:未知指令:FUNCTION

在Golang中有c FILE的数据类型吗?