Write to a file using fprintf() || File handling || C programming
In this program, we are going to write to a file using fprintf() with the help of C Programming Language.

 


#include <stdio.h>

void main()
{
    FILE *fptr;
    int rollno;
    char name[20];
    float marks;

    printf("Enter roll no.: ");
    scanf("%d", &rollno);

    printf("Enter name: ");
    fflush(stdin);
    gets(name);

    printf("Enter marks: ");
    scanf("%f", &marks);

    fptr = fopen("sample.txt", "w");

    fprintf(fptr, "%d %s %f", rollno, name, marks);
    fclose(fptr);
}

//.....coded by ANANYA MAURYA

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post