≡ Menu

c program

How To Show Line Numbers In vi / vim Text Editor

How do I display vi / vim text editor line numbers while writing a shell script or c program? How can I turn on or off this feature on Linux, Apple OS X, or Unix-like operating systems?
[click to continue…]

How you can run a c program in Linux?

Q. I've a c program and I'd like to run in Linux.

A. C program need to compile and run in Linux using cc or gcc command. When you invoke GCC (GNU C Compiler), it normally does preprocessing, compilation, assembly and linking for you. For example to compile hello.c program , type the following command:
cc -o hello hello.c
gcc -o hello hello.c

It will compile and produced an exectuable file called hello. To run program type:

If else statement in C Program

Q. Can you give me example for If else statement in C Program under Linux or TC?

A. C follows universal syntax for if..else. You can use any complier GNU Linux gcc or UNIX or old good TC.

if..else syntax

General if..else syntax is as follows:

if ( condition ) {
else  {

If given condition is TRUE, expr_set1 will get executed.
If given condition is FALSE (not TRUE), expr_set2 will get executed.

if..else example

Following example will find out large number from given input:

int main(){
        int x,y;
        printf("Enter value for x :");
        printf("Enter value for y :");
        if ( x > y ){
                printf("X is large number - %d\n",x);
                printf("Y is large number - %d\n",y);
        return 0;

Howto see output of C program in Linux or UNIX

Q. I am new to Linux but not to c programming. At university we are using Turbo C compiler under DOS/Windows XP to write and compile C programs. Under Linux I’ve small program called test.c. How do I compile and see the output of C program in Linux? Note I’m using Fedora Core Linux.

A. Under Linux you need to gcc (GNU project C and C++ compiler) command to compile a program. When you compile a program it generates an executable file called a.out.

gcc -o output-file program.c

Task: Compile program

To compile type the command:
$ gcc test.c

Task: Execute program to see output

Above command will create a file called a.out. To see output of test.c program type:
$ ./a.out

Task: Compile to specific executable file

You can specify an execuable file name while compiling program itself:
$ gcc -o test test.c
Now execute test (see output of test.c)
$ ./test

HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD

How do I compile C program and create an executable file under Linux or UNIX operating systems?
Sample Unix C Program
[click to continue…]

Linux / UNIX: Determine File Type

How do I determine the file type under UNIX or Linux like operating systems?
[click to continue…]