/* *************************************************
68 . To Read A FILE and Display its Contents
************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("test.c","r");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
else
{
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
else
printf("%c",ch);
}
fclose(fp);
getch();
}
OUTPUT
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("test.c","r");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
else
{
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
else
printf("%c",ch);
}
fclose(fp);
getch();
}
OUTPUT
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
printf("\n Welcome to C Language ");
getch();
}
#include<*conio.h>
void main()
{
clrscr();
printf("\n Welcome to C Language ");
getch();
}
/* *************************************************
69 . To Copy Contents of 1 FILE to Another
************************************************** */#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main
{
FILE *fs,*ft;
char ch;
clrscr();
fp=fopen("test.c","r");
if(fs==NULL)
{
puts("Cannot Open File");
exit(0);
}
ft=fopen("copy.c","r+");
if(ft==NULL)
{
puts("Cannot Open File");
exit(0);
}
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
{
fputc(ch,ft);
printf("%c",ch);
}
}
fclose(fs);
fclose(ft);
getch();
}
OUTPUT
#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
clrscr();
printf("\n Welcome to C Language ");
getch();
}
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
clrscr();
printf("\n Welcome to C Language ");
getch();
}
/* *************************************************
70 . To Merge Two FILES in to Single File
************************************************** */#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
FILE *fp1,*fp2,*fp3;
char c;
clrscr();
printf("Enter First File");
fp1=fopen("n1.data","w");
while(c=getchat()!=EOF)
putc(c,fp1);
fclose(fp1);
printf("Enter Second File");
fp2=fopen("n2.data","w");
while(c=getchat()!=EOF)
putc(c,fp2);
fclose(fp2);
fp1=fopen("n1.data","r");
fp2=fopen("n2.data","r");
fp3=fopen("n3.data","w");
while((c=getc(fp1))!=EOF)
putc(c,fp3);
fclose(fp1);
while(c=getc(fp2)!=EOF)
putc(c,fp3);
fclose(fp2);
fclose(fp3);
printf("The Merged File is :");
fp3=fopen("n3.data","r");
while((c=getc(fp3))!=EOF)
printf("%c",c);
fclose(fp3);
getch();
}
OUTPUT
Enter First File
Welcome To Loyola's ACS
Enter Second File
Satya rocks here...!!!
The Merged File is
Welcome To Loyola's ACS
Satya rocks here...!!!
0 comments:
Post a Comment