i would suggest u use something like the 'sliding window'
u move a buffer of some length a byte at a time (u can use fseek) and
do ur comparison within the buffer

u can generalize in the sense that the size of the buffer is
dynamically assigned etc

--- In [email protected], "exotic_umesh" <[EMAIL PROTECTED]> wrote:
>
> /*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 
> */
>


Reply via email to