Can't run .exe program in Windows

Started by ghoxxaz, April 24, 2014, 10:41:28 PM

Previous topic - Next topic

ghoxxaz

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

jj2007

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();
}

ghoxxaz

Thanks for the reply, and i Will test it the first thing tomorrow :)


Skickas från min iPhone via Tapatalk

czerny

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

TimoVJL

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\""
May the source be with you

ghoxxaz

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 :)

czerny

You should get a keypress after you display your text, not the other way around! czerny

ghoxxaz


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

czerny

#8
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;
}

ghoxxaz

Not sure, will try when i got home. thanks for replying :)


Skickas från min iPhone via Tapatalk

ghoxxaz

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

Stefan Pendl

You know that RETURN exits the function immediately without executing any code after it?
---
Stefan

Proud member of the UltraDefrag Development Team

ghoxxaz

Yeah, I looked it up in my pdf file yesterday


Skickas från min iPhone via Tapatalk