I need help in writing a single function which sets a small array (with 2 characters) to the ordinal suffix of a number.(Ordinals are 1st, 2nd, 3rd, 4th etc and the suffix refers to the letters.)
I need to write the function with the following signiture
void suffix(int n, char suff[]);
Assuming the following declarations
1 2 3
char s[5];
int x;
the result of a call:
suffix(x,s);
will return an appropriate string in s for any given positive value of x from 0 to 9999.
Any help/hints on writing the functtion would be great.
In else/if chains like this, it stops checking further conditions once the first matching condition is found. For example if you run 10013 through this if/else chain, it will match the first condition because n%100 == 13 returns true -- even though the number if out of range. This is why numbers are not even getting to your n > 9999 check.
To fix this, rearrange this chain so that the "higher priority" conditions are first. For instance you might want to make the > 9999 check the first in the chain since it's the most significant.