File Handling: Fprintf Write Content to a File

code:

#include<stdio.h>
#define SIZE 80
int main()
{
    FILE *fp;
    FILE *fpr;

    fp=fopen("E:/nosemsters/codes/crefresh/crefresh/c_for_technical_interview_udemy_course/file pointer/frmt.txt","r");
    if(fp==NULL)
    {
        printf("unable to open file\n");
        return 0;
    }

    fpr=fopen("E:/nosemsters/codes/crefresh/crefresh/c_for_technical_interview_udemy_course/file pointer/report.txt","w");

    if(fpr==NULL)
    {
        printf("unable to open file\n");
        return 0;

    }
    //prime read

    char names[SIZE];
    int salary;
    while(1)
    {
        fscanf(fp, " %[^,],%d", names, &salary);
        printf("%s gets $%d per hour\n",names,salary);
        fprintf(fpr,"%s gets $%d per hour\n",names,salary);

        if(feof(fp))
            break;
    }
    fclose(fp);


    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *