954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Closing a window in turbo c++ for windows

Hi people, need some help in closing the window after program execution has completed.
I am running Turbo c++ 4.5 for windows under Win7 32. Thanks.
Heres the sample code:

//Read and display test customer file

#include
#include
#include

struct customer
{
char c_name[50];
int i_age;
};

int main(void)
{
clrscr();
struct customer rec;
FILE *stream;
if((stream = fopen("Personel.dat", "r" )) == NULL)
{
cout << "Error opening file\n";
return 1;
}
while(!feof(stream))
{
fread(&rec, sizeof(rec), 1, stream);
{
if(feof(stream)) break;
}
cout << rec.c_name << " age " << rec.i_age << "\n";
};

fclose(stream);
cout << "\n\nEnd of file!";
getch();
return 0;
}

zbar
Newbie Poster
10 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Well, the line "getch();" is going to wait for the user to type a character before exiting the program. Remove it and the program will exit after printing "End of file!" and the console window will close.

mike_2000_17
Posting Virtuoso
Moderator
2,134 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

Thanks Mike_2000_17 for your response. I removed the getch() line but the window still wont close. Anything else I can do?

zbar
Newbie Poster
10 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

If it does print "End of file", then what you need to do to close the window is to click on the X in the upper right corner. Once it reaches the end of the program, if the window doesn't close by then, then there's nothing to put in your program that will close the window.

mike_2000_17
Posting Virtuoso
Moderator
2,134 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

I am not using that sample code for anything but pasted it for reference to my question. Yes it prints the files contents and the "End of file" but hangs there until I physically close the window. There has to be something that will close the console window surely?.

zbar
Newbie Poster
10 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Perhaps it has something to do with the fact that you're using a freaking ancient compiler with a state of the art OS. Do you have a similar problem with other free compilers that were written for something newer than Windows 3.1?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

You have a point there. I'll go dig up my old XT.

zbar
Newbie Poster
10 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 
#include <windows.h>
int main()
{
  //whatever
  DestroyWindow(GetActiveWindow());
  return 0;
}
tapaninyc
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You