>> You just need to treat the letters as numbers by typecasting them.
You don't need to typecast them at all ... characters are just numbers to the compiler, so you can just do :
char first_char, second_char;
if (first_char < second_char) {
/* first_char comes before second_char alphabetically */
}
else {
/* first_char comes after second_char alphabetically or they are the same characters */
}
Main Topics
Browse All Topics





by: archang3lPosted on 2007-09-16 at 03:08:31ID: 19900089
Hello thefirstfbli,
You mentioned you know how to sort numbers already. You just need to treat the letters as numbers by typecasting them.
i.e.
char a = 'a';
char b = 'b';
(int)a; // 65
(int)b; // 66
Regards,
archang3l