C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WILDCARD: output all a* by searching a text file

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
ume$h
Guest





PostPosted: Fri May 18, 2007 9:10 am    Post subject: WILDCARD: output all a* by searching a text file Reply with 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? */

#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





PostPosted: Fri May 18, 2007 9:10 am    Post subject: Re: WILDCARD: output all a* by searching a text file Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.