Hello, I am very very new to programming but after I was able to create the empty file and print the “Hello world” , I can’t seem to open the file, nothing happens. What I simply ask is what the output should look like and how I would know that I had done it right.
Trying to open the Hello world file
I’m not sure what could be going wrong but these are the steps that one should take. See if you have done something similar and we should be able to better help you. I am using C programming language for the example demonstrated.
-
Create a new file using Sublime Text and type in the code as shown below.
#include <stdio.h>
int main() {
printf(“Hello World\n”);
return 0;
} -
Save the file as
hello.c
. -
Compile the code by using command line interface/terminal app in your operating system by navigating to the directory containing the file and running the command:
gcc hello.c
(on macOS or Linux) -
Execute the program by running the command:
./a.out
-
If everything goes fine, you should see the output,
Hello World
in the terminal.
Thank you. If I may ask, would it work the same for python on windows? I am learning python myself and I am just starting to get the hang of it.
Yes, it should work similarly for Python on Windows. Only the code and the command to execute it would change. Also, Python code is interpreted and not compiled. That means you will type the code, save it in a file with .py extension and run it using the Python interpreter. Optionally, you can also start the Python interpreter (REPL) which is kind of like Python’s own command line, type and run your code then and there without saving it in a file.
Thank you once more. Is it alright if you shared the code and how to execute the command with me so that I can try and figure my way around it? Because when I still try to open the the hello world file I create, with the extension .py, it just opens the terminus for a split second then closes it; and even then, in that brief moment nothing is displayed. Also, it seems I can only build whatever is in my first line of code. Anything I write below it is not, well, printed. If you could kindly help me resolve this issue or at least try and identify the issue that would be a big help. So far you have been very kind, I’d appreciate any help I can get.
My apologies for taking so long to reply, was caught up by so much. Thank you so much, you have been a big help. Hope you have a wonderful day ahead.