/* Program: strcmp.c
 * ---------------------------------------------------------------------
 * This program re-implements the function strcmp of the standard
 * library and uses it to compare two strings, passed as command
 * parameters.
 * ---------------------------------------------------------------------
 * Nikolaos S. Papaspyrou (nickie@softlab.ntua.gr)
 * National Technical University of Athens
 * Department of Electrical Engineering
 * ---------------------------------------------------------------------
 * Course: Programming Techniques (2nd semester)
 * URL:    http://www.softlab.ntua.gr/~nickie/Courses/progtech/
 * ---------------------------------------------------------------------
 */


/* Header files */

#include <stdio.h>


/* Function my_strcmp */

int my_strcmp (const char * s1, const char * s2)
{
   while (*s1 == *s2 && *s1 != '\0') {
      s1++;
      s2++;
   }

   /* Here we assume that characters are unsigned (0-255) */

   return *s1 - *s2;
}


/* Main program */

int main (int argc, char * argv[])
{
   int result;

   if (argc != 3) {
      fprintf(stderr, "Usage: strcmp <string-1> <string-2>\n");
      return 1;
   }

   result = my_strcmp(argv[1], argv[2]);

   printf("\"%s\"", argv[1]);
   if (result == 0)
      printf(" = ");
   else if (result < 0)
      printf(" < ");
   else
      printf(" > ");
   printf("\"%s\"\n", argv[2]);

   return 0;
}

