Pelles C forum

C language => Beginner questions => Topic started by: ghoxxaz on April 24, 2014, 10:41:28 PM

Title: Can't run .exe program in Windows
Post by: ghoxxaz on April 24, 2014, 10:41:28 PM
Hi guys!

So I am new to programmering and i follow à pdf file i found on Google. My question is, when i have compiled the code and built it i can execute the code, and it is successfull.

But, when i try to double click the .exe file in Windows Explorer it opens but shuts down almost immediately. Why?

Appreciate some explonation :)




Skickas från min iPhone via Tapatalk
Title: Re: Can't run .exe program in Windows
Post by: jj2007 on April 24, 2014, 10:58:27 PM
Console applications close immediately unless you tell them to wait for a keypress...

...
#include <conio.h>   // for _getch()
...
int main(int argc, char* argv[]) {
...
  _getch();
}
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 24, 2014, 11:26:29 PM
Thanks for the reply, and i Will test it the first thing tomorrow :)


Skickas från min iPhone via Tapatalk
Title: Re: Can't run .exe program in Windows
Post by: czerny on April 25, 2014, 08:06:20 AM
Quote from: jj2007 on April 24, 2014, 10:58:27 PM
Console applications close immediately unless you tell them to wait for a keypress...
As an alternative: You can open a cmd shell and run it there.

czerny
Title: Re: Can't run .exe program in Windows
Post by: TimoVJL on April 25, 2014, 09:48:46 AM
With right mouse button
2ExpMenuCmd.reg
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\*]
[HKEY_CURRENT_USER\Software\Classes\*\shell]
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open With cmd]
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open With cmd\command]
@="\"cmd.exe\" \"/k %1\""
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 25, 2014, 02:14:07 PM
Thanks for the reply everyone! Appreciate it! :)

Well, the cmd window doesn't close as soon I double click the .exe file to run it, but it is a black cmd windows, and doesn't show the text unitl I hit a key but when the text shows up the cmd window closes.

---

#include <conio.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
      _getch();
      
   printf("\"Text that shows up!\"");
   return 0;
}
---

So, what am I doing wrong? hehe ^^ Please have patient with me :)
Title: Re: Can't run .exe program in Windows
Post by: czerny on April 25, 2014, 02:32:14 PM
You should get a keypress after you display your text, not the other way around! czerny
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 25, 2014, 02:56:13 PM

Quote from: czerny on April 25, 2014, 02:32:14 PM
You should get a keypress after you display your text, not the other way around! czerny

Yes, I understand what you mean, but when I tried to write  _getch(); after the text I didn't get any changes.


Skickas från min iPhone via Tapatalk
Title: Re: Can't run .exe program in Windows
Post by: czerny on April 25, 2014, 03:08:51 PM
Quote from: ghoxxaz on April 25, 2014, 02:56:13 PM
Yes, I understand what you mean, but when I tried to write  _getch(); after the text I didn't get any changes.
Have you compiled it?

#include <conio.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("\"Text that shows up!\"");
_getch();

    return 0;
}
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 25, 2014, 03:11:35 PM
Not sure, will try when i got home. thanks for replying :)


Skickas från min iPhone via Tapatalk
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 27, 2014, 12:38:57 AM
Solved :D I noticed that you czerny, wrote _getch(); after the text and before return. I wrote it after return so that was the problem :)


Skickas från min iPhone via Tapatalk
Title: Re: Can't run .exe program in Windows
Post by: Stefan Pendl on April 27, 2014, 08:51:51 AM
You know that RETURN exits the function immediately without executing any code after it?
Title: Re: Can't run .exe program in Windows
Post by: ghoxxaz on April 27, 2014, 11:14:45 AM
Yeah, I looked it up in my pdf file yesterday


Skickas från min iPhone via Tapatalk