Link to home
Start Free TrialLog in
Avatar of roglan
roglan

asked on

Search a file containing certain text....

How do I search a directory for all files or files like *.txt or .t?t for the occurrence of a searchstring like "Hello"?

Roger
ASKER CERTIFIED SOLUTION
Avatar of Triskelion
Triskelion
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of digized
digized

Do you know 'regular expressions'?
Do you know perl?
Do you want to do this in C?
Avatar of roglan

ASKER

I'm using a Borland Compiler 5.5.

I've had a look at the findfirst()/findnext methods, and thinks they look good, I'll come back when I've tried them out...thanks.

And yes: I want to do this in C, I do know a bit of Perl, but I'd prefferd to have this work in more or less standard C

Roger
strtok will only be useful if the search string is one word. I would suggest that you use the strstr() function instead.

This function is case-sensitive, if you wish to do a case insensitive search you could convert your seach string to uppercase using the strupr() function and then convert each line read from the file to uppercase before running the strstr() function (you may wish to copy the line into a second buffer to convert to uppercase so you have an unchanged copy to print out or you could keep track of your position in the file using the ftell() function then re-read any lines that you want to print out using the fseek() function).

Cheers - Gavin
Hello

You can use findfirst() & findnext functions.
You can have prototype of these functions defined in Turbo C help. Actually the solution which u want can be found in findfirst & findnext example given in that help. The is self-explanatory.
wish u all the best!!!!!!!!
bye
Parag
Avatar of roglan

ASKER

I've already got the answers I needed from newmang and Triskelion - Thanks guys!

Is there any way I can divide the points between you?
I don't know.
You'll have to ask the admin if that's possible.