Saving the output of a C program in a text file(Linux/Unix)

Consider the following c program

#include
main()
{
int i,n;
printf("Enter limit\n");
scanf("%d",&n);
printf("I will print %d times\n",n);
for(i=0;i

the output will be


Enter limit
4
I will print 4 times
I luv C
I luv C
I luv C
I luv C

This is a simple program which will print "I luv C" n times.Now, wouldn't be nice if we saved the output in a text file
then in such case you have to use directed symbol ">>"
(more...)


Important instructions for programs using math.h library function

if your program uses math.h header file then sometimes the compilation will lead to errors.In such cases you have to suffix -lm to the compilation file command

Usage

cc filename.c -lm

lm means link mathematical header file.Note that this step is not always required use it only if your program is correct and compilation is leading to errors.
and all other procedures are same.
(more…)


Advantages of running c in Linux/Unix-1

C is strongly linked with linux/unix .The kernel of Unix/Linux is written in C.Running C in linux/unit has several advantages .The most important among it is full word length utilization.
Consider the following C program

#include
int main()
{
int a;
float b;
printf("Size of int datatype =%d bits\n",(sizeof(a)*8));
printf("Size of float datatype =%d bits\n",(sizeof(b)*8));
return 1;
}

(more…)


C in linux/unix-First step

First let’s learn how to run a c program in linux/unix.Nearly every distro support’s running c programs.

First thing is to type the c program.you can use any editor you want but here i use vi editor which comes with allmost all distro

vi editor

To create a new c file or to open an existing c file,type vi followed by filename.c
ex:
[student@localhost student]$vi adi.c

will create a new file adi.c or will open an exisiting file adi.c if it’s present

now press insert key to edit or modify or add new content
after you complete writing the program,press Esc key and type :w (colen w) and press enter to save the file then press :q (colen q) and press enter to exit the vi editor.
(more…)