I'm modifying a 10-year old open-source utility written in C, even though I'm a PHP programmer, so the whole pointer business for working with strings is giving me a headache. Can anyone advise on why this string conversion snippet is not converting case?
#include <ctype.h>
int set_keysig (s, ks, init)
char s[];
struct KEYSTR *ks;
int init;
{
int sf, ok, l, rc;
char w[81], *c, *r;
int ktype, add_pitch, root, root_acc;
c = s;
/* ... omitting irrelevant, working code here ... */
/* this is where the word w is supposed to be extracted from the line of text c* and also converted to lowercase. The word gets extracted correctly in all cases, but it does not get converted to lowercase - each letter in the word is mysteriously remaining in its original case. */
r = w;
*r++ = *c++;
while (*c && (*c != ' ') && (*c != '+') && (*c != '-'))
*r++ = tolower(*c++);
*r ='\0';
/* the next line is how I'm checking whether the above lines worked */
if (verbose>=20) printf ("word: <%s>\n", w);
}
More context: I'm now compiling this code using gcc 4.2 in XCode 3.1 on an Intel Mac. This code used to work fine when I previously compiled it years ago using gcc 3 in XCode 2 on either a PowerPC Mac or an Intel Mac.
Any ideas?