Answer to Question #208661 in C for Swetha

Question #208661

Write a C program for File Operations to read a string from standard input and prints the entered string using fgets() and fputs() function.


1
Expert's answer
2021-06-20T08:12:04-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS