C Program to Write a Sentence to a File | Program Clips

Опубликовано: 07 Октябрь 2024
на канале: Program Clips
1,533
23

#Cprogram
Source Code:
//Program to Write a Sentence to a File
#include stdio.h
#include stdlib.h
void main()
{
char sentence[1000];
// creating file pointer to work with files
FILE *fptr;
// opening file in writing mode
fptr = fopen("program.txt", "w");
// exiting program
if (fptr == NULL) {
printf("Error!");
exit(1);
}
printf("Enter a sentence:\n");
fgets(sentence, sizeof(sentence), stdin);
fprintf(fptr, "%s", sentence);
fclose(fptr);
}
//Check a file named program in your folder