1 #include <stdio.h> 2 3 #define ARGS 3 /* Two strings + the program name */ 4 5 typedef enum { 6 OK, 7 ERROR_PROGRAM_INVOCATION, 8 ERROR_NULL_POINTER, 9 } status_t; 10 11 status_t validate_arguments(int argc, char *argv[]); 12 13 int main (int argc, char *argv[]) 14 { 15 status_t st; 16 int cmp; 17 18 if((st = validate_arguments(argc, argv))) return st; 19 20 cmp = 0; 21 for(size_t i = 0; argv[1][i] && argv[2][i]; i++) { 22 cmp += ((argv[1][i]) - (argv[2][i])); 23 } 24 25 printf("%d\n", cmp); 26 return 0; 27 } 28 29 status_t validate_arguments(int argc, char *argv[]) 30 { 31 if(!argv) return ERROR_NULL_POINTER; 32 if(argc != ARGS) return ERROR_PROGRAM_INVOCATION; 33 34 return OK; 35 }