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
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();
}
Thanks for the reply, and i Will test it the first thing tomorrow :)
Skickas från min iPhone via Tapatalk
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
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\""
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 :)
You should get a keypress after you display your text, not the other way around! czerny
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
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;
}
Not sure, will try when i got home. thanks for replying :)
Skickas från min iPhone via Tapatalk
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
You know that RETURN exits the function immediately without executing any code after it?
Yeah, I looked it up in my pdf file yesterday
Skickas från min iPhone via Tapatalk