Upload
prasanna-venkatesh
View
216
Download
0
Embed Size (px)
Citation preview
7/31/2019 7 Ex
1/10
REG NO:312211106072
SOURCE CODE:
#include
void main()
{
char c[100],b[100];
char m,n;
int k=1;
FILE *f1;
FILE *f2;
f1=fopen("file1.txt","w");
f2=fopen("file2.txt","w");
printf("Enter the text for file 1:");
gets(b);
fputs(b,f1);
printf("\nEnter the text for file 2:");
gets(c);
fputs(c,f2);
fclose(f1);
fclose(f2);
f1=fopen("file1.txt","r");
f2=fopen("file2.txt","r");
while(m!=EOF && n!=EOF)
7/31/2019 7 Ex
2/10
REG NO:312211106072
{
m=fgetc(f1);
n=fgetc(f2);
if(m!=n)
{
k=0;
break;
}
}
if(k==1)
printf("\nThe files are identical");
else
printf("\nThe files are different");
fclose(f1);
fclose(f2);
}
OUTPUT:
Enter text for file 1:
Hello!I am Prasanna
Enter text for file 2:
India is great
The files are different
7/31/2019 7 Ex
3/10
REG NO:312211106072
SOURCE CODE:
#include
void main()
{
char b[100];
char m,n;
FILE *f1;
FILE *f2;
f1=fopen("file1.txt","w");
printf("Enter the text for file 1:");
gets(b);
fputs(b,f1);
fclose(f1);
f1=fopen("file1.txt","r");
f2=fopen("file2.txt","w");
printf("\nContents of file1:\n");
m=fgetc(f1);
while(m!=EOF)
{
printf("%c",m);
fputc(m,f2);
m=fgetc(f1);
7/31/2019 7 Ex
4/10
REG NO:312211106072
}
fclose(f1);
fclose(f2);
f2=fopen("file2.txt","r");
printf("\nContents of file2:\n");
n=fgetc(f2);
while(n!=EOF)
{
printf("%c",n);
n=fgetc(f2);
}
fclose(f2);
}
OUTPUT:
Enter the text for file 1:
India is my country
Contents of file1:
India is my country
Contents of file2:
India is my country
7/31/2019 7 Ex
5/10
REG NO:312211106072
SOURCE CODE:
#include
void main()
{
char b[100];
char m;
int a=0,v=0,w=1,l=0,c=0,s=0,h=0;
FILE *f1;
f1=fopen("file1.txt","w");
printf("Enter the text for file 1:");
gets(b);
fputs(b,f1);
fclose(f1);
f1=fopen("file1.txt","r");
while(m!=EOF)
{
m=fgetc(f1);
a++;
if(m=='a' || m=='e' || m=='i' || m=='o' || m=='u')
v++;
else if(m==' ')
7/31/2019 7 Ex
6/10
REG NO:312211106072
w++;
else if(m=='.')
l++;
else if(m==',')
c++;
else if(m==';')
s++;
else if(m=='#')
h++;
}
fclose(f1);
printf("\nThe number of characters:%d",a-1);
printf("\nThe number of vowels:%d",v);
printf("\nThe number of words:%d",w);
printf("\nThe number of lines:%d",l);
printf("\nThe number of commas:%d",c);
printf("\nThe number of semicolons:%d",s);
printf("\nThe number of hashes:%d",h);
}
OUTPUT:
Enter the text for file 1:
Vowelsare #a,e,i,o,u.
7/31/2019 7 Ex
7/10
REG NO:312211106072
The number of characters:20
The number of vowels:9
The number of words:2
The number of lines:1
The number of commas:4
The number of semicolons:0
The number of hashes:1
7/31/2019 7 Ex
8/10
REG NO:312211106072
SOURCE CODE:
#include
void main()
{
char b[100],c[100];
char m,n,l;
FILE *f1;
FILE *f2;
FILE *f3;
f1=fopen("file1.txt","w");
f2=fopen("file2.txt","w");
printf("Enter the text for file 1:");
gets(b);
fputs(b,f1);
printf("\nEnter the text for file 2:");
gets(c);
fputs(c,f2);
fclose(f1);
fclose(f2);
f1=fopen("file1.txt","r");
f2=fopen("file2.txt","r");
f3=fopen("file3.txt","w");
7/31/2019 7 Ex
9/10
REG NO:312211106072
printf("\nContents of file 1:\n");
m=fgetc(f1);
while(m!=EOF)
{
printf("%c",m);
fputc(m,f3);
m=fgetc(f1);
}
fclose(f1);
printf("\nContents of file 2:\n");
n=fgetc(f2);
while(n!=EOF)
{
printf("%c",n);
fputc(n,f3);
n=fgetc(f2);
}
fclose(f2);
fclose(f3);
f3=fopen("file3.txt","r");
printf("\Contents of file 3:\n");
while(l!=EOF)
7/31/2019 7 Ex
10/10
REG NO:312211106072
{
l=fgetc(f3);
printf("%c",l);
}
fclose(f3);
}
OUTPUT:
Enter the text for file 1:
I am prasanna.
Enter the text for file 2:
This is my record.
Contents of file 1:
I am prasanna.
Contents of file 2:
This is my record.
Contents of file 3:
I am prasanna. This is my record.