Write a program to display number 1 to 100. Redirect the output of the program to text file.
CODING:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fs1,*fs2,*ft;
char ch,file1[20],file2[20],file3[20];
clrscr();
printf("Enter name of first file:");
gets(file1);
printf("Enter name of Second file:");
gets(file2);
printf("Enter name of file which will store contents of two files:");
gets(file3);
fs1=fopen("1.txt","r");
fs2=fopen("2.txt","r");
ft=fopen("file3.txt","w");
while((ch=getc(fs1)) !=EOF)
{
putc(ch,ft);
while((ch=getc(fs2)) !=EOF)
putc(ch,ft);
printf("Succefully");
}
fclose(fs1);
fclose(fs2);
fclose(ft);
getch();
}
CODING:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fs1,*fs2,*ft;
char ch,file1[20],file2[20],file3[20];
clrscr();
printf("Enter name of first file:");
gets(file1);
printf("Enter name of Second file:");
gets(file2);
printf("Enter name of file which will store contents of two files:");
gets(file3);
fs1=fopen("1.txt","r");
fs2=fopen("2.txt","r");
ft=fopen("file3.txt","w");
while((ch=getc(fs1)) !=EOF)
{
putc(ch,ft);
while((ch=getc(fs2)) !=EOF)
putc(ch,ft);
printf("Succefully");
}
fclose(fs1);
fclose(fs2);
fclose(ft);
getch();
}
Comments
Post a Comment