Write and Read a whole String from a file || File handling || C programming
In this, we are going to see a program to write and read a whole String from a file with the help of C Programming Language.

 


#include <stdio.h>
#define SIZE 50

void main()
{
    FILE *fptr;
    char s1[SIZE], s2[SIZE];

    printf("Enter any string: ");
    gets(s1);

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

    fclose(fptr);

    fptr = fopen("sample.txt", "r");
    fgets(s2, SIZE, fptr);

    printf("You entered: ");
    puts(s2);
}

//.....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