2023-12-25 00:13:17 +00:00
|
|
|
#include <stdio.h> /* fprintf(3), stderr */
|
2023-12-25 22:58:47 +00:00
|
|
|
#include <stdlib.h> /* EXIT_FAILURE */
|
2023-12-26 03:49:29 +00:00
|
|
|
#include <sysexits.h>
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|