| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

StrEqu

This version was saved 16 years ago View current version     Page history
Saved by Kenneth Finnegan
on April 13, 2008 at 9:51:40 am
 

A clear way to compair two strings to see if they're equal.

 

Code:

#include <string.h>

if(!strcmp(s1, s2)) // This is a BAD way to do it, it's counterintuitive because ! means not.

 

#define Strequ(s1, s2) (strcmp((s1), (s2)) == 0)

if(Strequ(s1, s2)) // This make a lot more sense as to what you're testing

 


Extensions:

#define StrRel(s1, op, s2) (strcmp(s1, s2) op 0)

Then call it with:

StrRel(s1, ==, s2);

StrRel(s1, !=, s2);

StrRel(s1, <=, s2);

 


Sources:

http://c-faq.com/style/strcmp.html

Comments (0)

You don't have permission to comment on this page.