C Program to Write a Sentence to a File



 c program to write a sentence to a file

Learn C - C tutorial - c program to write a sentence to a file - C examples - C programs

C Program to Write a Sentence to a File

  • File is created for permanent storage of data.
  • It is a pre-defined structure.

Sample Code

#include <stdio.h>
#include <stdlib.h>  
int main()
{
    char sentence[1000]="work done by wikitechycom";
    FILE *fptr;
    fptr = fopen("program.txt", "w");
    if(fptr == NULL)
    {
        printf("Error!");
        exit(1);
    }
    printf("work done by wikiechy.com\n");
    fprintf(fptr,"%s", sentence);
    fclose(fptr);
    return 0;
}

Output

work done by wikiechy.com


View More Quick Examples


Related Searches to C Program to Write a Sentence to a File