Question:
write a program to store every character typed at the keyboard into a file. the procedure should come to an end as soon as character ~ is hit from the keyboard.
I've coded and it is working fine but the only problem I'm facing is that I'm unable to check for the character ~ and terminate the program.
here's the coding which I've done
/*program to make the user enter the text from the keyboard and write them on to a file*/
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *fp;
char ch;
fp=fopen("d:\\mannu\\try2.txt","w");
if(fp==NULL)
{
puts("\nCannot open file");
exit(1);
}
printf("\nEnter the characters ");
while((ch=getc(stdin))!='\n')
{
if(ch=='~')
{
fclose(fp);
exit(1);
}
else
{
fputc(ch,fp);
}
}
fclose(fp);
}
thanx in advance......
and also I'm glad the way I'm getting the response & help from u all......and hope the same in future.
feeling myself lucky to be around such helpful persons
bye