I would like to check if the first letter of a string is before or after the letter t
in the alphabet.
For example, the user inputs "Brad" and it would print
"Your name starts with a letter that comes before "t"."
Something of that sort.
I would like to check if the first letter of a string is before or after the letter t
in the alphabet.
For example, the user inputs "Brad" and it would print
"Your name starts with a letter that comes before "t"."
Something of that sort.
Something like below (add checks for null and if it the first character is t itself, etc).
#include <stdio.h>
#include <stdlib.h>
/* t's value in ASCII */
#define LETTER_T 116
int main(int argc, char * argv[])
{
/* Use toupper or tolower functions to handle casing */
char * str = "brad";
char * result = (str[0] < LETTER_T) ? "before" : "after";
printf("%s starts with a %c that comes %s the letter t.", str, str[0], result);
return 0;
}