In this tutorial we will see how to use the strcmp() function.
It returns:
We need the string.h include to use this function.
Let's see this example of the strcmp() function:
// compare.c
#include <stdio.h>
#include <string.h>
int main(int ac, char *av[])
{
char *word;
int cmp;
word = "badprog";
cmp = strcmp(av[1], word);
if (!cmp)
printf("Match, indeed, strcmp = %d\n", cmp);
else
printf("Do not match, indeed, strcmp = %d\n", cmp);
return (0);
}
Compiling and executing:
gcc compare.c && ./a.out badprog
Result:
Match, indeed, strcmp = 0
Interesting isn't it?
© Badprog - I want to change the world. And I will.
Add new comment