Malina Malina - 4 months ago 11
C Question

Does some kind of 'strcmpf' implementation exists?

I am looking for a function that checks if a string follows (matches exactly) the pattern of data specified by the additional arguments corresponding to the

format
string
Like this:

/* int strcmpf (char *str1, char *format, ...); */
char *test = "Hello World !"

if(!strcmpf(test, "%s%*s %c", "Hello ", '!')
return HELLO_HAS_BEEN_SAID;
else
return PROGRAM_ISNT_POLITE;


Implementing this myself I assume will be very difficult, but such function could be very useful for semantic parsing of content. Before I attempt to write such function myself, I need to know if there is already a library or code snippet that provides implementation of a function like this ?




To be more specific, I need pattern-matching behavior. So
test
must match exactly the pattern specified by the data corresponding to the
format
parameter.

Answer

I need to know if there is already a library or code snippet that provides implementation of a function like this

The standard library has no such functionality. Requests for third-party library recommendations are off-topic here, but to the extent that I understand the functionality you want, I am anyway unaware of an existing third-party implementation.

As I said in comments, I suggest that you design the pattern-matching aspect around bona fide regular expressions instead of around printf() or scanf() formats (which are not entirely the same). There are several regular expression libraries available to support that part.