U
ume$h
/*program to search a* in a text file & write output in a file.*
indicated any character. IT IS WORKING BUT HOW TO GENERALISE IT FOR A
LONG STRING
LIKE umesh*** OR Suppose I want to find all words in a text file which
starts with 'a'
and ends with 'z' i.e a*z
where * denotes a string of characters. How can I do it? */
#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,ch;
while((c=getc(f))!=EOF && (ch=getc(f))!=EOF )
{
if(c=='a'&& ch!=' ')
fprintf(fp,"%c%c\n",c,ch);
}
fclose(f);
fclose(fp);
return 0;
}
/* INPUT
abc
abc
abd
ap
OUTPUT
ab
ab
ab
ap
*/
indicated any character. IT IS WORKING BUT HOW TO GENERALISE IT FOR A
LONG STRING
LIKE umesh*** OR Suppose I want to find all words in a text file which
starts with 'a'
and ends with 'z' i.e a*z
where * denotes a string of characters. How can I do it? */
#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,ch;
while((c=getc(f))!=EOF && (ch=getc(f))!=EOF )
{
if(c=='a'&& ch!=' ')
fprintf(fp,"%c%c\n",c,ch);
}
fclose(f);
fclose(fp);
return 0;
}
/* INPUT
abc
abc
abd
ap
OUTPUT
ab
ab
ab
ap
*/