C program which copies one file contents to another file.

C Program which copies one file contents to another file. Here we read the one file and copies the characters to another file which are existed in the disc. Here we read the file names from the command line.Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>
#include <conio.h>
#include <process.h>

void main(int argc, char *argv[])
{
FILE *fs,*ft;
char ch;
clrscr();
if(argc!=3)
{
puts("Invalid number of arguments.");
exit(0);
}
fs = fopen(argv[1],"r");
if(fs==NULL)
{
puts("Source file cannot be opened.");
exit(0);
}
ft = fopen(argv[2],"w");
if (ft==NULL)
{
puts("Target file cannot be opened.");
fclose(fs);
exit(0);
}
while(1)
{
ch=fgetc(fs);
if (ch==EOF)
break;
else
fputc(ch,ft);
}
fclose(fs);
fclose(ft);
getch();
}

Read more Similar C Programs
File operations

Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to generate random numbers.

C Program to generate random numbers. Random Numbers are numbers which are produced by a process and its outcome is unpredictable.The function srand() is used to seed the random sequence. The rand() function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}] with a period of at least 2^32.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main() {
int i, num;
printf("Enter how many random numbers you want?n");
scanf("%d", &num);
//The function srand() is used to seed the random sequence.
//srand() will generate a specific "random" sequence over and over again.
srand(time(NULL));
//The rand() function shall compute a sequence of pseudo-random
//integers in the range [0, {RAND_MAX}] with a period of at least 2^32.
for (i = 0; i < num; i++) {
printf("random_number[%d]= %dn", i + 1, rand());
}

printf("A number between 0 and 99: %dn", rand() % 100);

printf("A number between 0 and 9: %dn", rand() % 10);

return 0;
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to show Sleep() function example.

C Program to show Sleep() function example.
sleep() function stops the execution of the program, wherever its invoked or called. It takes the arguments in microseconds. In Windows we use Sleep() function i,e ‘S’, and for other systems it is sleep() function.
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <time.h>
#include <stdio.h>
#include <windows.h> 
#include <conio.h>

int main()
{
 printf("This is the message before sleep() function");
 Sleep(1000); //1000 microsecond= 1 second will sleep...
 printf("This is the message after 1 second");
 getch();
 return 0;
}

However, I have to remind you that the program may change a bit based on
what Operating system and compiler you are using.

Read more Similar C Programs
Learn C Programming
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!


List of C Programs
(c) www.c-program-example.com

C Program to perform complex numbers operations using structure.

C Program to perform complex numbers operations using structure. Complex numbers are numbers which contains two parts, real part and imaginary part. Complex numbers are written as a+ib, a is the real part and b is the imaginary part. We used the structure in C to define the real part and imaginary part of the complex number.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include<stdio.h>
#include<math.h>

void arithmetic(int opern);

struct comp
{
double realpart;
double imgpart;
};

void main()
{
int opern;
clrscr();
printf("nn ttt***** MAIN MENU *****");
printf("nn Select your option: n 1 : ADDn 2 : MULTIPLYn 0 : EXIT nntt Enter your Option [ ]bb");

scanf("%d",&opern);

switch(opern)
{
case 0:
exit(0);
case 1:
case 2:
arithmetic(opern);
default:
main();
}

}

void arithmetic(int opern)
{

struct comp w1, w2, w;

printf("n Enter two Complex Numbers (x+iy):n Real Part of First Number:");
scanf("%lf",&w1.realpart);
printf("n Imaginary Part of First Number:");
scanf("%lf",&w1.imgpart);
printf("n Real Part of Second Number:");
scanf("%lf",&w2.realpart);
printf("n Imaginary Part of Second Number:");
scanf("%lf",&w2.imgpart);


switch(opern)
{

/*addition of complex number*/
case 1:
w.realpart = w1.realpart+w2.realpart;
w.imgpart = w1.imgpart+w2.imgpart;
break;

/*multiplication of complex number*/
case 2:
w.realpart=(w1.realpart*w2.realpart)-(w1.imgpart*w2.imgpart);
w.imgpart=(w1.realpart*w2.imgpart)+(w1.imgpart*w2.realpart);
break;
}


if (w.imgpart>0)
printf("n Answer = %lf+%lfi",w.realpart,w.imgpart);
else
printf("n Answer = %lf%lfi",w.realpart,w.imgpart);
getch();
main();
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!


List of C Programs
(c) www.c-program-example.com

C Program to convert a Roman numeral to its decimal equivalent.

C Program to convert a Roman numeral to its decimal equivalent. Roman numbers are the oldest number system used in ancient Rome. They use the combination of letters from Latin alphabet to represent the system. We used the if-else and for statements to solve this problem. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

void main()
{

int *a,len,i,j,k;
char *rom;

clrscr();

printf("Enter the Roman Numeral:");
scanf("%s",rom);

len=strlen(rom);

for(i=0;i<len;i++)
{
if(rom[i]=='I')
a[i]=1;
else if(rom[i]=='V')
a[i]=5;
else if(rom[i]=='X')
a[i]=10;
else if(rom[i]=='L')
a[i]=50;
else if(rom[i]=='C')
a[i]=100;
else if(rom[i]=='D')
a[i]=500;
else if(rom[i]=='M')
a[i]=1000;
else
{
printf("nInvalid Value");
getch();
exit(0);
}
}
k=a[len-1];
for(i=len-1;i>0;i--)
{
if(a[i]>a[i-1])
k=k-a[i-1];
else if(a[i]==a[i-1] || a[i]<a[i-1])
k=k+a[i-1];
}
printf("nIts Decimal Equivalent is:");
printf("%d",k);
getch();
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!


List of C Programs
(c) www.c-program-example.com

C program to find the 2’s complement of a binary number.

C Program to calculate the 2’s complement of a binary number. 2’s complement of a number is obtained by scanning it from right to left and complementing all the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>
#include<conio.h>

void complement (char *a);
void main()
{
char a[16];
int i;
clrscr();
printf("Enter the binary number");
gets(a);
for(i=0;a[i]!=''; i++)
{
if (a[i]!='0' && a[i]!='1')
{
printf("The number entered is not a binary number. Enter the correct number");
exit(0);
}
}
complement(a);
getch();
}
void complement (char *a)
{
int l, i, c=0;
char b[16];
l=strlen(a);
for (i=l-1; i>=0; i--)
{
if (a[i]=='0')
b[i]='1';
else
b[i]='0';
}
for(i=l-1; i>=0; i--)
{
if(i==l-1)
{
if (b[i]=='0')
b[i]='1';
else
{
b[i]='0';
c=1;
}
}
else
{
if(c==1 && b[i]=='0')
{
b[i]='1';
c=0;
}
else if (c==1 && b[i]=='1')
{
b[i]='0';
c=1;
}
}
}
b[l]='';
printf("The 2's complement is %s", b);
}



Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com