U
Umesh
/*program to search a* in a text file & write output in a file.*
indicated any character*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *f,*fp;
f=fopen("c:/1.txt","r");
if(f==NULL) { puts("Error opening file");exit(0);}
fp=fopen("c:/2.txt","w");
char c[2];
for(int i=1;i<3;++i)
{
while((c=getc(f))!=EOF)
if(c[1]=='a'&& c[2]!=' ')
fprintf(fp,"%c\n",c);
}
fclose(f);
fclose(fp);
return 0;
}
/*
INPUT c:/1.txt
abc
abc
abd
ap
OUTPUT c:/2.txt
a
a
a
a
REQUIRED OUTPUT c:/2.txt
ab
ab
ab
ap
*/
indicated any character*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *f,*fp;
f=fopen("c:/1.txt","r");
if(f==NULL) { puts("Error opening file");exit(0);}
fp=fopen("c:/2.txt","w");
char c[2];
for(int i=1;i<3;++i)
{
while((c=getc(f))!=EOF)
if(c[1]=='a'&& c[2]!=' ')
fprintf(fp,"%c\n",c);
}
fclose(f);
fclose(fp);
return 0;
}
/*
INPUT c:/1.txt
abc
abc
abd
ap
OUTPUT c:/2.txt
a
a
a
a
REQUIRED OUTPUT c:/2.txt
ab
ab
ab
ap
*/