Raoul Crisan
Raoul Crisan

Reputation: 55

Replacing an asterisk to make the strings equal , but how?

I have to write a funcion that checks if two strings are equal. If so it returns 1 otherwise 0. But, if the second string contains a replaceable asterisk it will be replaced in order to make the strings equal.For example "main.c" and "*.c" are equal because "main" can be replace with "*". How do i implement this ? Using strcmp ?

Upvotes: 0

Views: 179

Answers (1)

user149341
user149341

Reputation:

If you're allowed to use all C library functions, there's one that does this:

if (fnmatch("*.c", "main.c", 0)) {
    // it's a match
}

See the manual page for details.

Upvotes: 4

Related Questions