Write a C program for File Operations to read a string from standard input and prints the entered string using fgets() and fputs() function.
#include <stdio.h>
#include <stdlib.h>
void main( void){
char enteredString[100];
FILE *fpFile;
printf("Enter the string: ");
fgets(enteredString,100,stdin);
fpFile = fopen("file.txt", "w+");
fputs(enteredString, fpFile);
fclose(fpFile);
printf("\nThe entered string has been saved to the file \"file.txt\"\n\n");
getchar();
getchar();
}
Comments
Leave a comment