command line coursera
To compile a C program from the command line, follow these steps:
- Open a terminal or command prompt.
- Navigate to the directory where your C program is located using the
cd
command. - Once in the correct directory, use the
gcc
command followed by the name of your C file and the-o
option to specify the name of the output file. For example:gcc myprogram.c -o myprogram
. - Press Enter to execute the command. If there are no errors in the code, this will generate an executable file in the same directory.
- To run the compiled program, type
./
followed by the name of the executable file and press Enter. For example:./myprogram
. - The program will then execute, and you will see the output in the terminal.