I'm trying to make a makro to compare strings.
And yeah, I admit it, it's a school-task.
But it's just a task we were given "for fun" by a fellow student that runs our group-exercises, it's nothing I have to do, or anything that will benifit me.
We was asked to write a makro on this form:
Code:
#define STREQ(s1,s2) ((...))
That can compare 2 null-terminated strings to check if they are equal.
It should also be able to be used inside if's like this:
Code:
if(STREQ(string1, "TEST")) ...
I have thought of this for several hours now, and still havent got anywhere.
I first thought of this solution:
Code:
#define STREQ(s1,s2) ((s1 == s2) 1 ? 0)
But this only checks the adress of the memory-adress of the first element in each array.
I then thought of doing something ugly like this:
Code:
#define STREQ(s1,s2) \
{ \
for(int i=0; i < strlen(s1); i++) \
} \
It's not complete, but you get the idea... but I couldent get this to work, because it have to be able to expand inside an IF.
The only thing I can think of now, is to wrap a searching-function inside the STREQ makro...but that would remove the whole point of making a makro like this.
And when Im into that topic, I really dont see the point of learning stuff like this at the university, but oh well.
In any case, I am very interested in knowing how to do this ........, after trying for hours.
Or even better, if anyone could confirm my theory that this task is impossible