Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
void main()
{
clrscr();
char ch;
ofstream sc;
sc.open("om.txt");
while(ch!='1')   //here is the problem
{
ch=getche();
sc.put(ch);


}
sc.close();
getch();
}



The above enters one character at a time in text file om.txt. Problem is that program is not correctly teriminated when i press two time 1 then program terimate
Posted

Probably because you end the program with a call to getch. This also reads a character from the keyboard before it continues...
 
Share this answer
 
you check for the char '1' but you should check for the digit 1.

Be sure that you are fetching the proper char with getche():
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900