簡體   English   中英

將 printf 命令寫入或保存到文本文件(c 編程)

[英]writing or saving the printf command to a text file (c programming)

如何將 printf 內容保存/寫入文本文件?

我使用 puts() 但它沒有用。

還有其他評論可以使用嗎?

#include<stdio.h>
#include<string.h>
int main()
{
    /*declare and initialise variable*/
    char message[32][114],buffer[114];
    int i=1;
    FILE *input_file;
    FILE *output_file;

    input_file=fopen("exon11.txt", "r");
    output_file=fopen("1.txt", "w");

    /*stores and prints the data from the string*/
    while(fgets(buffer,114,input_file))
        {
            strcpy(message[i],buffer);
            /*fputs(message[i],file_out);*/
            printf(">%d\n%s\n\n",i,message[i]);
            i++;
    }

    getchar();
    return 0;

}

提前謝謝你

您可以使用fprintf將數據寫入文件。

#include<stdio.h>
#include<string.h>
int main()
{
    /*declare and initialise variable*/
    char message[32][114],buffer[114];
    int i=1;
    FILE *input_file;
    FILE *output_file;

    input_file=fopen("exon11.txt", "r");
    output_file=fopen("1.txt", "w");

    /*stores and prints the data from the string*/
    while(fgets(buffer,114,input_file))
        {
            strcpy(message[i],buffer);
            /*fputs(message[i],file_out);*/
            fprintf(output_file,">%d\n%s\n\n",i,message[i]);
            i++;
    }

    getchar();
    return 0;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM