CamelCase in C

Example for versions gcc 3.4.5, gcc 4.2.4, tcc 0.9.25

This example is based on character-wise string processing. fgets here reads at most 99 characters into the string, and stops when it finds end-of-string character, so a long line might be split. C doesn’t provide boolean data type, so it has to be simulated using integer variable.

#include <stdio.h>

void main() {
    char text[100],cc[100];
    fgets(text, sizeof text, stdin);
    int i,j=0,lastSpace=1;
    for (i=0; text[i]!='\0'; i++) 
        if (text[i]>='A' && text[i]<='Z' || text[i]>='a' && text[i]<='z')
        {   if (lastSpace>0)
                cc[j] = toupper(text[i]);
            else
                cc[j] = tolower(text[i]);
            j++;
            lastSpace = 0;
        }
        else
            lastSpace = 1;
    cc[j]='\0';
    printf("%s\n",cc);
}