Thread: Camel Case!!!!

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    5

    Camel Case!!!!

    Hey I'm building this program to take the user's input and produce 1.The entered Data 2.The string in lower case. 3.the string in upper case. 4. the string with the first letter of each word capitalized. 5. the string in camel case.

    I have everything running smooth except for camel case at the end. Please can someone help me code the end? I'd appreciate it a lot!

    Code:
    #include <stdio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    void toUpper(char *str);
    void toLower(char *str);
    void toFirstCap(char *str);
    void toCamelCase(char *str);
    
    int main(int argc, char **argv)
    {
     char sentence[256];
     char ch; 
     int i = 0;
    
    
    printf("Enter a string: ");
    gets(sentence);
    
    printf("\nYour Sentence:%s\n",sentence);
    toLower(sentence);
    
    printf("\nLower case:%s\n",sentence);
    toUpper(sentence);
    
    printf("\nUpper case: %s\n",sentence);
    toFirstCap(sentence);
    
    printf("\nFirstCap case: %s\n",sentence);
    toFirstCap(sentence);
    
    
    //printf("\nCamel case: %s\n",sentence);
    //toCamelcase(sentence);
    
    
    system("pause");}
    
    
    
    void toUpper(char *str)
     {
      while(*str != '\0')
       {
       if(*str >= 'a' && *str <= 'z')
        { 
         *str -= 'd' - 'D';
        } 
       str++; 
       }  
     }
    
    
    
    void chngCaseSingleCharacter(char *str, int cAse)
     {
     if(cAse == 2)
     {
      if(*str >= 'a' && *str <= 'z')
      {
       *str -= 'd' - 'D';}
       else if(cAse == 1)
        {
         if(*str >= 'A' && *str <= 'Z')
          {
           *str += 'd' - 'D';
        }}
    }}
    
    
    
    void toLower(char *str)
     {
      while(*str != '\0')
     {
       if(*str >= 'A' && *str <= 'Z')
        { 
         *str += 'd' - 'D';
        } 
       str++; 
      }
     }
    
    
    
    void chngCasesingleCharacter(char *str, int cAse)
     {
     if(cAse == 2)
     {
      if(*str >= 'a' && *str <= 'z')
       {
        *str -= 'd' - 'D';
       }
      else if(cAse == 1)
       {
        if(*str >= 'A' && *str <= 'Z')
          {
           *str += 'd' - 'D';
       }}
    }}
    
    
    
    void toFirstCap(char *str)
    {
     char b;
      while( (b = *str++) != '\0')
       {
       if(b == ' ' || b == '\t')
        {
        if(*str >= 'a' && *str <= 'z')
        { 
         *str -= 'd' - 'D'; 
        }
        }
       else
        {
         if(*str >= 'A' && *str <= 'Z') 
          {
           *str += 'd' - 'D'; 
        }}
    }}
    
    
    
    void toFirstCapSmartWay(char *str)
     {
      char b; 
      while( (b = *str++) != '\0')
       { 
        if(b == ' ' || b == '\t') 
       {
         chngCaseSingleCharacter(str, 2);
       }
        else 
         {
          chngCaseSingleCharacter(str, 1);
         }
       }   
     }
    
    //void toCamelCase(char *str)
    //put code 4 camel case here//

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What the hell is camel case?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Yes, I was wondering the same thing. Apparently it exists:

    CamelCase - Wikipedia, the free encyclopedia

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So ... what then? He wants to cap the first letter of each word and remove spaces? Alright, let's see your attempt.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > gets(sentence);
    Read the FAQ
    Read SourceForge.net: Gets - cpwiki
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    Quzah, Camelcase is like the following:

    Standard - HelloWorld
    CamelCase - hElLoWoRlD

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    Quote Originally Posted by UltraKing227 View Post
    Quzah, Camelcase is like the following:

    Standard - HelloWorld
    CamelCase - hElLoWoRlD

    What you're referring too as CamelCase is actually StudlyCaps

    CamelCase Wiki

    CamelCase (also spelled camel case or camel-case) or medial capitals[1] is the practice of writing compound words or phrases in which the elements are joined without spaces, with each element's initial letter capitalized within the compound, and the first letter is either upper or lower case—as in "LaBelle", BackColor, "McDonald's", or "iPod". The name comes from the uppercase "bumps" in the middle of the compound word, suggestive of the humps of a camel....

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by UltraKing227
    Quzah, Camelcase is like the following:

    Standard - HelloWorld
    CamelCase - hElLoWoRlD
    I disagree (I consider what you call "Standard" as camel case), but obviously it depends on the definition that eligilbert12 has in mind.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Mar 2010
    Posts
    5
    I mEaNt LiKe ThIs. CoUlD yOu PlEaSe HeLp Me CoDe It?

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by eligilbert12 View Post
    I mEaNt LiKe ThIs. CoUlD yOu PlEaSe HeLp Me CoDe It?
    I'd call that Retarded Case.
    It's simple. Just iterate over your string and switch the case of each letter to the opposite case of the previous letter.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  12. #12
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Quote Originally Posted by cpjust View Post
    I'd call that Retarded Case.
    I second that! Lmao!
    The keyboard is the standard device used to cause computer errors!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-01-2009, 09:54 AM
  2. Segmentation fault!?!?!?
    By Viper187 in forum Windows Programming
    Replies: 57
    Last Post: 10-02-2008, 09:40 PM
  3. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  4. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM