me-utils/src/strcmp.c

46 lines
699 B
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "support.h"
int shortestword(const char* word1, const char* word2)
{
int len = 0;
for(;;)
{
if(!word1[len])
{
return 0;
}
else if(!word2[len++])
{
return 1;
}
}
}
int main(int argc, char **argv)
{
int swl = 0;
/* modify the program to support comparison of an arbitrary number of strings */
if(argc != 3)
{
throw(NEEDARG_FAIL, mastrcat(argv[0], " str1 str2"));
}
if(!shortestword(argv[1], argv[2]))
{
swl = (int) strlen(argv[1]);
}
else
{
swl = (int) strlen(argv[2]);
}
return(strncmp(argv[1], argv[2], swl));
}