Answer to Question #219085 in C for Vishnukumar

Question #219085
Write a program to read character by character from the user and write them into a file. Read the same data from the file and display that on the screen(use fputc(), fgetc(), rewind() functions).
1
Expert's answer
2021-07-20T10:03:00-0400
#include<stdio.h>
#include<conio.h>
void main()
{
	FILE *fp;
	char character='p';
	fp=fopen("characters.txt", "wb+");
	while(character!=' '){
		printf("Enter the character (space to stop): ");
		scanf("%c",&character);
		fflush(stdin);
		if(character!=' '){
			fputc(character,fp);
		}
	}
	rewind(fp);     
	printf("\nReading characters from the file: \n");
	while((character=fgetc(fp))!=EOF){
		printf("%c\n",character);
	}
	fclose(fp);
	getch();
	getch();
}





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