Hello World cannot run

Code:
// Simple C program to display "Hello World"
 
// Header file for input output functions
#include <stdio.h>
 
// main function -
// where the execution of program begins
int main()
{
 
   // prints hello world
   printf("Hello World");
 
   return 0;
}

Code:
#include <stdio.h>

int main()
{
   printf("Hello World!\r\n");
   return 0;
}


I installed Visual Studio Code and Msys2, updated mingw-w64, and I used both the above codes to make a hello program.
I used both VSCode and Dev C++ to compile it.
it says compiled successfully. and an exe file is generated on desktop. but when I tried to run the exe file,
it can't open. it was like it was about to open and flash but suddenly it is terminated and closed..
how do I suppose to know that the hello program functions correctly??

Edit: I've configured the settings to Path and installed Code Runner on VSCode...but to no avail
This is because it opens in a command prompt, but because you don't have the command prompt open it opens briefly and closes.

Run cmd.exe from your run dialog, navigate to the directory your program is in, and type its filename then hit enter, and it will run without the window closing.
I'm using Terminal, does it make a difference? Because I run Terminal on VSCode, and it managed to compile but cannot run. Does that mean I cannot run it on Terminal after it's been compiled?

Edit: Oh ok ok I got it, I am going to that now, run from command prompt

Edit 2: It still cannot run :/
A screenshot of your Windows command prompt in the correct directory of the executable would be more helpful than just "it cannot run."
A console program will automatically close after it's done running. Since it's only executing a single statement, it is probably finishing execution and then closing before you can get a chance to see it.

A common approach that Windows C programmers use to get around this is to put a getchar() call right before the final return statement. This will cause the program to stop and wait for the user to press a key on the keyboard before it closes.

Try it like this, and then you shouldn't need to worry about using a command prompt to execute the program.
C:
// Simple C program to display "Hello World"
 
// Header file for input output functions
#include <stdio.h>
 
// main function -
// where the execution of program begins
int main()
{
 
   // prints hello world
   printf("Hello World");
 
   getchar();
   return 0;
}
A console program will automatically close after it's done running. Since it's only executing a single statement, it is probably finishing execution and then closing before you can get a chance to see it.

A common approach that C programmers use to get around this is to put a getchar() call right before the final return statement. This will cause the program to stop and wait for the user to press a key on the keyboard before it closes. I'm surprised that whatever tutorial or book you're using didn't mention that.

Try it like this, and then you shouldn't need to worry about using a command prompt to execute the program.
C:
// Simple C program to display "Hello World"
 
// Header file for input output functions
#include <stdio.h>
 
// main function -
// where the execution of program begins
int main()
{
 
   // prints hello world
   printf("Hello World");
 
   getchar();
   return 0;
}
Hi, I followed your suggestion, I downloaded and installed Visual Studio Community 2022..
but there's no C language in the options..
Hi, I followed your suggestion, I downloaded and installed Visual Studio Community 2022..
but there's no C language in the options..
...he was telling you to add a single line to the program you already wrote and had executed. You shouldn't have needed additional software for this.
A console program will automatically close after it's done running. Since it's only executing a single statement, it is probably finishing execution and then closing before you can get a chance to see it.

A common approach that C programmers use to get around this is to put a getchar() call right before the final return statement. This will cause the program to stop and wait for the user to press a key on the keyboard before it closes. I'm surprised that whatever tutorial or book you're using didn't mention that.

Try it like this, and then you shouldn't need to worry about using a command prompt to execute the program.
C:
// Simple C program to display "Hello World"
 
// Header file for input output functions
#include <stdio.h>
 
// main function -
// where the execution of program begins
int main()
{
 
   // prints hello world
   printf("Hello World");
 
   getchar();
   return 0;
}
It worked! Though I don't have idea as why it didn't and now does

...he was telling you to add a single line to the program you already wrote and had executed. You shouldn't have needed additional software for this.
But shouldn't VS Community also able to do it? @Arthran 's trick works, but I still cannot run code compiled from Visual Studio Community
It worked! Though I don't have idea as why it didn't and now does
Arthran described it pretty clearly. What part of that post don't you understand?
I already told you. Im zero at programming, and Im not technology savvy, I am not familiar nor intermediately acquainted with programming

Edit: I know there's googling and everything, but thats why we have forums, to communicate and speak. and you cant just go around speaking to noob and nobody expecting them to totally understand what you said. Tone down a lil bit, will ya
I already told you. Im zero at programming, and Im not technology savvy, I am not familiar nor intermediately acquainted with programming
You already wrote and compiled a program that you were able to run, the only problem was it didn't stay on your screen long enough to see the output.

All Arthran was telling you to do was use the same software you used to write that program to add a single additional line to it, recompile it, and it should no longer have the issue you mentioned.
You already wrote and compiled a program that you were able to run, the only problem was it didn't stay on your screen long enough to see the output.

All Arthran was telling you to do was use the same software you used to write that program to add a single additional line to it, recompile it, and it should no longer have the issue you mentioned.
See, this is how the vibes of learning should be, precise, concise, not too criticise. Thank you @Trihan I understand it better now. Thanks for relaying without superior know it all tone

You already wrote and compiled a program that you were able to run, the only problem was it didn't stay on your screen long enough to see the output.
Thanks for being able to perceive my situation perfectly. Apology for not providing with screenshot

@Arthran by the way, I was using Dev-C++ and Visual Studio Code, and Visual Studio Community
@ATT_Turan Hey..why did you react to my post with a sad emoji. Im sorry if I was being rude, all you were trying to do was help me..sorrry
There's absolutely nothing in Arthran's post that was superior or know it all. It explained that the program was probably running fine but closing too quickly for you to see it (which Trihan also said in his very first reply).

It also explained what the line you were told to add does:
This will cause the program to stop and wait for the user to press a key on the keyboard before it closes.

So when you proceed to say
I don't have idea as why it didn't and now does
that's concerning because you should know exactly why - it was explained in that post.

No one has said anything to you in any kind of rude or criticizing way, but your "I'm a noob and I don't know anything about computers" schtick can only last so long. It is presumed that once someone answers a question or explains a thing, you will understand it from that point on. That's your responsibility as the learner and asking other people for help, and it's not rude to say so.
You know, you really should let this one go..
And I wasnt refering Athran, I was referring you.
And you are right, my presumption of tone here it outta place,
so for now Im just gonna ignore you,
tone down, ok?
@Trihan already explained to me, why do you bother to continue on? To show how mighty in programming you are?

You understand coding, but you don't know how to use the right tone when speaking. There's different tone to everyone.
And I wasnt refering Athran, I was referring you.
That makes zero sense. You asked for help. You were given an answer. You said you didn't understand the answer, so I asked you which part you didn't understand.

There is no "tone" in that, it literally is asking which part didn't you understand so it can be explained.
My communication with Arthran make sense and we have no problem at all. I wasnt referrring to Arthran, why are you trying to roping him/her in?
You are the one whos problematic to me on this thread that I'm reffering to. I was saying that you dont know how to use the right tone. Listen, if you are talking to newbie, you go to their level, otherwise they cant imagine your intellect. All you did was straight-objective communicating. That's why I said tone down.
Bloody hell this forum is not an exam hall devoid of emotion.
I downloaded and installed Visual Studio Community 2022..
but there's no C language in the options
Visual Studio Community isn't really meant for C. There technically is a way to compile C code with it, but it's not recommended. Visual Studio Code + MinGW is a good combination for the C language. Dev-C++ is probably fine too, though I haven't used it before.

But just for the record, what I recommended to you in that other thread wasn't C. Rather, it was C#. Even though the names are almost the same, they are very different languages.

You can certainly learn C if you want, and in fact, a lot of University Computer Science programs do use C to teach students the basics of programming, so it might not be a bad idea to start off with C. However, I want to make sure that you're aware that it would be difficult to use C to make the types of applications that you were talking about in the other thread.

If you start off with C, just make sure that you understand that it will only be the first step in your journey, and that you will likely need to move on to another language afterwards.

You understand coding, but you don't know how to use the right tone when speaking.
For what it's worth, I don't believe that ATT_Turan was trying to be rude to you. It looks to me that he was only trying to help you.

I think that perhaps you're feeling a bit overwhelmed from trying to learn a bunch of unfamiliar things, and it caused you to read his post with a defensive mindset, and maybe the tone that you pictured in your mind when you read it is different from the tone that he had in his mind when he wrote it.

I understand that it can feel bad when you're having a tough time comprehending something that other people might consider to be basic, and sometimes when we feel that way, we might project those negative feelings onto other people and assume that they're looking down on us. But I assure you that nobody in this thread is looking down on you. We're all just trying to help. We all know what it's like to be new to programming, because we all started from zero at some point.

If you read somebody's post with a defensive mindset, you will very likely miss some important things. But if you assume that the person is saying whatever they're saying with your best interest in mind, I guarantee that you will have an easier time learning whatever they're trying to teach you.

You're trying to self-learn something that many people have to go to college to learn. In other words, you have a potentially tough road ahead of you, and there are probably going to be many times when you feel this type of frustration, and there are probably going to be many times when you will need to reach out to people for help.

Frankly speaking, you can't afford to take things personally and waste time worrying about whatever tone you think people should be using each time. IMO, it's in your best interest to set your ego aside and just focus on trying to absorb any information you can, from any person who is willing to give it to you (regardless of their tone).

Sorry if that sounded preachy. I'm just weighing in with my opinion, for the sake of what I consider to be your best interest.
Visual Studio Community isn't really meant for C. There technically is a way to compile C code with it, but it's not recommended. Visual Studio Code + MinGW is a good combination for the C language. Dev-C++ is probably fine too, though I haven't used it before.

But just for the record, what I recommended to you in that other thread wasn't C. Rather, it was C#. Even though the names are almost the same, they are very different languages.

You can certainly learn C if you want, and in fact, a lot of University Computer Science programs do use C to teach students the basics of programming, so it might not be a bad idea to start off with C. However, I want to make sure that you're aware that it would be difficult to use C to make the types of applications that you were talking about in the other thread.

If you start off with C, just make sure that you understand that it will only be the first step in your journey, and that you will likely need to move on to another language afterwards.


For what it's worth, I don't believe that ATT_Turan was trying to be rude to you. I looks to me that he was only trying to help you.

I think that perhaps you're feeling a bit overwhelmed from trying to learn a bunch of unfamiliar things, and it caused you to read his post with a defensive mindset, and maybe the tone that you pictured in your mind when you read it is different from the tone that he had in his mind when he wrote it.

I understand that it can feel bad when you're having a tough time comprehending something that other people might consider to be basic, and sometimes when we feel that way, we might project those negative feelings onto other people and assume that they're looking down on us. But I assure you that nobody in this thread is looking down on you. We're all just trying to help. We all know what it's like to be new to programming, because none of us were born with that knowledge.

If you read somebody's post with a defensive mindset, you will very likely miss some important things. But if you assume that the person is saying whatever they're saying with your best interest in mind, I guarantee that you will have an easier time learning whatever they're trying to teach you.

You're trying to self-learn something that many people have to go to college to learn. In other words, you have a potentially tough road ahead of you, and there are probably going to be many times when you feel this type of frustration, and there are probably going to be many times when you will need to reach out to people for help.

Frankly speaking, you can't afford to take things personally and waste time worrying about whatever tone you think people should be using each time. IMO, it's in your best interest to set your ego aside and just focus on trying to absorb any information you can, from any person who is willing to give it to you (regardless of their tone).

Sorry if that sounded preachy. I'm just weighing in with my opinion, for the sake of what I consider to be your best interest.
I second this. It's important to understand that we're all doing this voluntarily. We might get a little snarky at times, but we're still trying to offer help, otherwise we wouldn't say anything at all.
I wasnt referrring to Arthran, why are you trying to roping him/her in?
Because I had only said two things - one was that you should provide screenshots when you're having problems (which is completely standard practice), and the second was asking you which part of Arthran's explanation you didn't understand, at which point you jumped down my throat.

I don't see anything I said that's trying to "rope Arthran" into anything.

I was saying that you dont know how to use the right tone.
I used, and have continued to use, zero "tone." You are making up this attitude that you think I have. It is not in any of the words I've used to you.

All you did was straight-objective communicating. That's why I said tone down.
I have no idea what that means.

Bloody hell this forum is not an exam hall devoid of emotion.
It should be - the only emotion in this thread is being created by you. Everyone else has been communicating factually. There's no reason for any emotions to be involved when you're talking about the functionality of computers.
Thanks @Trihan @Arthran for correcting my discipline, I can see now how I have defensive mindset. I haven't been actively on forum long enough to apply what I learnt in moral education and church classes during middle school, or to look the other way.

And @ATT_Turan , I hope you accept my apology for misconstruing your posts and intention.

All in all, I was attempting to contribute to the already colloquially friendly vibes by everyone in here.
But just as there's tone to everyone it is also rightful and incontrovertible for @ATT_Turan to exercise his choice of tone.

I think I get it.

Since this is a technically a programming thread, it only makes sense for us to commune objectively, much less subjectively.

For my best interest, and for y'all willingness to spare some change and chains of thoughts onto me, @Trihan @Arthran and @ATT_Turan , I thank you

Original thread: https://forums.rpgmakerweb.com/threads/hello-world-cannot-run.154340/