harakit/src/strcmp.c

25 lines
517 B
C
Raw Normal View History

#include <stdio.h> /* fprintf(3), stderr */
#include <stdlib.h> /* EXIT_FAILURE */
#include <sysexits.h>
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;
}