OK, here's two ideas:
#1)
Make an array for suffixes. Initalize it with values that match the right suffix, to the right index to the array value, for any number. (You don't say how high you're going with these ordinals).
Then you can print up the right suffix by using the array index:
Say you want to print 12th. You'd use:
Code:
printf("%d%s", ordinal,suffix[ordinal]);
Because suffix[12] = "th"
#2)
Make a separate function for this, and again using a single suffix[] array entry (3 char's probably), you'd have your logic to get the right suffix, in a single switch() statement:
Code:
//when the suffix ordinal is declared:
suffix[2] = '\0']; //set EOS char
//in the getSuffix() function:
void getSuffix(int ordinal) {
switch (ordinal) {
case < 2: suffix[0] = 's'; suffix[1] = 't'; break; //st
case < 4; suffix[0] = 'r'; suffix[1] = 'd'; break //rd
case < 20: //th and the rest of your logic
}
}
//then:
getSuffix(ordinal)
printf("%d%s", ordinal, suffix);
You'll need all your logic, but this is an easy way to shrink it down to something more manageable, concise, and clear.
Whatever string you use, be sure it has the end of string char immediately after the last char. Otherwise, it's just a couple of char's, and not a string.