Problem
Write a program that will take characters from the keyboard, one at a time, and writes them to a file. Use fputc function.Solution - Code
#include<stdio.h>#include<stdlib.h>
int main()
{
char ch;
FILE *ft;
int i;
printf ("NOTE: If you want to exit, just press 1 and hit enter.\n\n");
ft = fopen ("P3.txt","w");
while (1)
{
printf ("Enter Character : ");
scanf("%c",&ch);
fflush (stdin);
if ( ch == '1' )
break;
else
fputc (ch,ft);
}
fclose (ft);
system ("pause");
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.