Write a program that reads two strings of characters, and indicates their lexicographic precedence in the character code of the machine (here: ASCII code).


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#define size 50
int main () 
{
    char STR1[size], STR2[size];
    int I;
    
    printf ("Enter the first string : ");
    gets (STR1);
    printf ("Enter the second string : ");
    gets (STR2);
  
    for (I = 0; (STR1[I] == STR2[I]) && STR1[I] && STR2[I]; I++);
  
    if (STR1[I] == STR2[I])
        printf ("\"%s\" is equal to  \"%s\"\n", STR1, STR2);
    else if (STR1[I] < STR2[I])
        printf ("\"%s\" precedes \"%s\"\n", STR1, STR2);
    else
        printf ("\"%s\" precedes \"%s\"\n", STR2, STR1);
  
    return 0;
}


Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Cuckoo hashing