Implementing wild card searching in c

I want to implement wildcard searching in c. Please tell me how to do it. Or where to start for this problem

Regards
Harsh
If this is for an assignment to implement wildcard searches. iirc the course is taught using state machines.

Otherwise if it's incidental to your app, regex is what you need..
you can find the code in so many unix applications. most of the unix app's takes wild card searches. look into the source code of any small application. like ls, grep, find etc etc.. you can even debug them and understand how they are working.
The shell is what implements the wildcard pattern, not the tool (grep, etc).

(Try strace ls * and see what the execve system call shows).

Your reply looks quite surprising to me Jsmith. This exactly means, if i am writing an application which takes some parameters, i don't have to implement wild cards in my program.
Example:

strace ls *

Output:

execve("/bin/ls", ["ls", "Accumulate.h", "a.out", "Die.h", "Die_orig.h", "main.cpp", "UniformRandom.h"], [/* 49 vars */]) = 0

(etc, etc.)

Please give me some algo.. I am not able to understand the parameters that are given in programs available on internet
yes JSmith you are correct. Wild Characters are implemented in shell only. I have tested with this code:

1
2
3
4
5
6
int main(int argc, char** argv)
{
        std::cout << "Number of chars supplied :" << argc << std::endl;

        return 0;
}


now run this prog with ./a.out D*

Here is the output:
Number of chars supplied :3


This when i have 2 directories starting with 'D'.

make sure that there are more than 1 filename/directory in your current directory. The answer shall be > 2, which means that the program is getting more arguments than actually provided.

Harsh:
As you want to implement this then you will get all the parameters in your 'argv' variable and you have to use a loop and then handle all those accordingly.
closed account (z05DSL3A)
I want to implement wildcard searching in c. Please tell me how to do it. Or where to start for this problem.


Where to start for this problem? Try giving more information about what you are wanting to achieve. Just saying you want to implement wild-card searching doesn't give a lot of information.
Debug the shell code then.. :D

Ankit/Jsmith thats good.. i was not knowing this.
Last edited on
Topic archived. No new replies allowed.