bonsix/src/strcmp.c

26 lines
518 B
C
Raw Normal View History

#include <stdio.h> /* fprintf(3), stderr */
#ifndef EX_USAGE
# include <sysexits.h> /* EX_USAGE */
#endif
static char *program_name = "strcmp";
int main(int argc, char *argv[]){
int i;
if(argc < 3){
fprintf(stderr, "Usage: %s [string] [string...]\n",
argv[0] == NULL ? program_name : argv[0]);
return EX_USAGE;
}
for(; *argv[1] != '\0'; ++argv[1])
for(i = 2; i < argc; ++i)
if(*argv[i-1] > *argv[i])
return 1;
else if(*argv[i-1] < *argv[i]++)
return -1; /* actually 255 */
return 0;
}