You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
699 B
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));
|
|
}
|