Quantcast
Viewing all articles
Browse latest Browse all 10

How to Compile and Run a C program in Linux?

Image may be NSFW.
Clik here to view.

Do you wish to know howto write, compile and execute C Program in Linux platform? Then you are at right place.In this tutorial I will show you howto code and run C Program in Linux terminal. Image may be NSFW.
Clik here to view.
:)

1. Goto Linux Terminal.
2. Type Vi Filename.C

Image may be NSFW.
Clik here to view.

In the above screenshot I have given filename as 2038bug.c

3. The Vi Editor will open.

Note:
To know more about commands used in VI editor checkout,
Vim/Vi Editor Commands Cheat Sheet
4. Press I to insert text and start writing the C Program into it.
5. After coding it.Just press Esc button and type :wq
Note:
Here :wq specifies save and exit.

Image may be NSFW.
Clik here to view.

How to Compile C Program In Linux Terminal ?

6. The next step after coding is compilation part.To compile C Program type the following in Terminal,
CC Filename.c
If you had any error again enter into text editor,
Vi Filename.c after fixing the error press :wq (Save and exit).

7. Now execute the program to see the Output
Type ./a.out
The output of the program will be displayed. Image may be NSFW.
Clik here to view.
;)

Image may be NSFW.
Clik here to view.

That’s it Image may be NSFW.
Clik here to view.
:)
In this tutorial I have simulated a Year 2038 bug or Y2k38 using C Program. The following ANSI C programme when compiled simulates the bug. Image may be NSFW.
Clik here to view.
;)

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
int main (int argc, char **argv)
{
time_t t;
t = (time_t) 1000000000;
printf (%d, %s, (int) t, asctime (gmtime (&t)));
t = (time_t) (0x7FFFFFFF);
printf (%d, %s, (int) t, asctime (gmtime (&t)));
t++;
printf (%d, %s, (int) t, asctime (gmtime (&t)));
return 0;
}

Output :
1000000000, Sun Sep 9 01:46:40 20012147483647,
Tue Jan 19 03:14:07 2038-2147483648,
Fri Dec 13 20:45:52 1901

Source Code taken from here



Viewing all articles
Browse latest Browse all 10

Trending Articles