Saving the output of a C program in a text file(Linux/Unix)
Welcome to my blog
.If you’re new here, you may want to subscribe to my full RSS feed. Thanks for visiting!Consider the following c program
[-]?View Code C1
2
3
4
5
6
7
8
9
10
#include<stdio.h>
main()
{
int i,n;
printf("Enter limit\n");
scanf("%d",&n);
printf("I will print %d times\n",n);
for(i=0;i<n;i++)
printf("I luv C\n");
}
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 [...]
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 [...]
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
[-]?View Code C1
2
3
4
5
6
7
8
9
#include<stdio.h>
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;
}
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 [...]

