Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exe problem... clicking on exe != Execute program 2

Status
Not open for further replies.

TalosBlack

Programmer
Jan 6, 2004
33
0
0
US
When i double click on the exe of my program I get a window to come up with a black screen and a flashing cursor. It seems as if the program is in some kind of infinite loop before i output anything to the screen. However, when i am in C++ (MS Visual Studio 6) and hit ctrl 5 ... or the execute program icon my program runs as exspected querrying the user for information and performs it's operation. I tried deleting the last build and rebuilding everything and still have the same problem. Any suggestion on why that might be or what to do would be great.

Thanks,
John

The following is my code until the first cout<< which never occurs when i double click the .exe.

//some headers

//Function Prototypes

//Global Variables

ofstream out("FilesToUpdate.txt");
ofstream outInvalid("InvalidLinks.txt");
ifstream in("Data.txt");
ifstream inPath("Paths.txt");

void main( void )
{
//variable declaration
char initialpath[MAX_PATH];

char temp[25];

do
{
inPath.getline(temp,15);
}while((strncmp(temp, "PATHS TO CHECK",14)) != 0);

char junk[MAX_PATH];
inPath.getline(junk, MAX_PATH);

//Loop that ins files
while(!inPath.eof())
{
char ATversion[10];
inPath.getline(ATversion, MAX_PATH);
inPath.getline(initialpath, MAX_PATH);
inPath.getline(pathofC, MAX_PATH);


out<<"\n************"<<endl;

while(OutputFlag != 0)
{//Encase of invalid entry
if(OutputFlag == 1)
break;
cout<<"Would you like ..."<<endl;


and so on... Note: the flags are properly intialized. As shown by working properly when i'm in c++. I didn't include the headers and variable declaration because that gets lengthy.

Thanks
 
I'm not sure about the syntax of your first loop:

do
{
inPath.getline(temp,15);
}while((strncmp(temp, "PATHS TO CHECK",14)) != 0);

That looks more like a BASIC loop than a c++ loop. Maybe you can do it that way, but your second loop is the more traditional way to write it. So maybe try it like this, but make sure you initialize temp to some 14 character string:

const char* temp = "myrandomstring";
while(strncmp(temp, "PATHS TO CHECK",14)){
inPath.getline(temp,15);
}

Also, while are you passing void to void main? You really shouldn't pass anything to void main:

void main(){
}

Hopefully someone else can confirm my thoughts. I'm no expert, but thoes two places look completely foreign to me.
 
May be it's not a program problem. Try press Alt-Enter with your black screen and flashing cursor. I think you get an ordinal console window.
I think you have full screen mode when start console application with double click. It's your current Windows setting. Correct it if you wish.
Your 1st input loop does not check EOF condition (Ctrl-Z in console input). Correct this too...
 
First Thanks. I haven't solved my problem yet but i know what to look into now. I usually wouldn't pass anything to main but i was looking at an example while writing some of this code. I took out the void same problem. I think the do loop should work but i changed it anyway. Still had the same probelm. at first i didn't know what ArkM meant by i didn't check eof and then i understood better and put in a statement to account for that. For some reason i am reaching eof when i execute the program by clicking it's exe but not while i am in visual studio. This strikes me as odd the eof condition shouldn't be reached. (My window wasn't maximized and i'm not really sure what that would cause to go wrong but i didn't play with ctrl-z for a minute ;) ) I'll play around more with the loop and see if i can figure out what is going on or a work around.

If anyone has further advice let me know.

Thanks

John
 
Ok problem solved. The poblem was this line of code:
ifstream inPath("Paths.txt");

I was exspecting to get certain things from this file. I never received them. Apparently when you click on the .exe the assumed path is that of the exe. drive:\somefoled\otherfolder\debug\filename.txt
(assuming you don't move your exe from where c++ creates it)
and when you run the program from c++ the assumed file is your workspace drive:\somefoled\otherfolder\filename.txt
Therefore i was reading in nothing when i was exspecting data...so i got stuck in an infinite loop i guess until eof and then the program either kept looping or just sat there.

Thanks a lot for all your help especially ArkM for noting i didn't check for the eof condition.

John
 
you can (sometimes, depending on OS and exe type) change this if you want... it's part of the program properties you get if you right-click on the icon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top