 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
ume$h Guest
|
Posted: Fri May 18, 2007 9:10 am Post subject: WILDCARD: output all a* by searching a text file |
|
|
/*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
*/ |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Fri May 18, 2007 9:10 am Post subject: Re: WILDCARD: output all a* by searching a text file |
|
|
ume$h wrote:
| Quote: | /*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? */
Read up on regular expressions and find a regex library. Boost.Regex is |
a good place to start.
--
Ian Collins. |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|