Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
C


1. C
C in a lower level general purpose programming language.

2. CentOS installation
The C compiler is part of a collection of development tools.

The following Linux command(s) install the GNU Development Tools.
sudo yum -y group install "Development Tools"

Note: Other languages my use these same development tools. The command need be run only once.

3. Verify the version
The following Linux command(s) verify the installed version of C.
gcc --version

On 2019-08-04 the output was as follows.
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


4. Hello world in C
The file type of a C program file is c.

The following Linux command(s) create/edit a hello program in the your home directory using the nano text editor.
nano ~/hello.c

Create the following program text in the editor that will output the text "Hello world"
#include int main() {    printf ("Hello world\n");    return 0;    }

To exit with save, remember to press Ctrl-X, then "y" (for yes) and Enter to exit.

The following Linux command(s) run the program.
gcc ~/hello.c -o ~/hello ~/hello

The output should be as follows.
Hello world


5. Class and lab
In the classroom, and for submissions, a makefile is used that hides the details of what is happening. The above is what can be used without using the makefile.

In the classroom and lab, many students use CygWin (a pretend Linux under Windows). Since Windows wants executable files to have the .exe file extension, the following is used in class. Linux does not need the .exe but it does not cause any issues. The following is more similar to what is used in class and in the labs.

Note also that

6. Hello world in C
The file type of a C program file is c.

The following Linux command(s) create/edit a hello program in the your home directory using the nano text editor.
nano ~/hello.c

Create the following program text in the editor that will output the text "Hello world"
#include int main() {    printf ("Hello world\n");    return 0;    }

To exit with save, remember to press Ctrl-X, then "y" (for yes) and Enter to exit.

The following Linux command(s) run the program.
gcc ~/hello.c -o ~/hello.exe ~/hello.exe

The output should be as follows.
Hello world


7. End of page