View Single Post
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#79
Originally Posted by virusforu View Post
~/MyDocs/files $ vi hellowrold.c //create a c program by using vi editor
Weird spelling of the file name. Especially as you're trying to compile hello.c later on.

Note : for entering any letter you should press “I” to enter in to insert mode
#inlcude <stdio.h>
main()
{
Printf(“M. Reddi Prasad Reddy,IP University,Delhi”);
}
Note: to save the files click ESC and shift+: and wq! .so that your c program will be saved.
It's spelled "include". The function you're looking for is "printf".

ESC leaves insertion mode. The command to save and quit is "wq" by itself and one enters command mode using ":".

~/MyDocs/files $ gcc-4.2 hello.c // gcc compiler will compile your c program
~/MyDocs/files $ ls // you will find the output file
a.out hello.c
Use -o flag to give the generated binary a name.

~/MyDocs/files $ sudo gainroot //shell root will be enabled
~home/usr/MyDocs/files # cp a.out /usr/bin // to see the output you should copy this outputfile to bin folder
~/usr/bin # chmod +x a.out // change the permissions
~/usr/bin # ./a.out
Why copy the binary to /usr/bin to then run it using ./a.out ?
 

The Following 2 Users Say Thank You to Joorin For This Useful Post: