c - Changing upper to lower and lower to upper -
i new in c programming. ask if function ok, because don't know how check in main.
char uppertolowertoupper(char ch) { if (ch>='a' && ch<='z') { ch=tolower(ch); return ch; } else if (ch>='a' && ch<='a') { ch=toupper(ch); return ch; }
it may appear work you, improved.
- firstly, it's incomplete. you're missing bracket (and
return statement) @ end. - next, not c implementations use ascii. if use code on systems ebcdic character set, you'd find
ch>='a' && ch<='z'includes more alphabet characters, , similarch>='a' && ch<='z'... suggest usingisupper,islowerinstead. - finally,
tolower,toupperexpect arguments of typeint.chararguments convertedintthere's more that... arguments supposed eitherunsigned charvalues oreof. else undefined behaviour, meaning signed character values pass these functions might cause segfaults (e.g. this question). recommend changing function acceptsunsigned charargument (instead ofcharargument) , returnsunsigned char.
Comments
Post a Comment