Thread: NEED HELP! make first letter of each word in user input text uppercase

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    23

    NEED HELP! make first letter of each word in user input text uppercase

    Hello,
    I am in need of some major help.
    I need to write a C program to make the user input some text,
    and the first letter of each word has to be uppercase.
    (have to use while loops)

    So for example lets say the user inputs:
    i lOvE pRoGrAmMiNg
    The output needs to be:
    I Love Programming

    Code:
    #include <stdio.h>
    int main()
    {
      int i = 0;
      char c, lower_c;
    
      printf("Enter text\n");
    
      c = getchar();
      while (c != '\n' && c >= 0)
    {
          if (c >= 'A' && c <= 'Z')
            lower_c = c + 32;
          else
            lower_c = c;
    
          putchar(lower_c);
    
          c = getchar();
    }
    I have started this code by making the letters lowercase (I don't know if this was the right way to approach this, but I am hoping you can help me with that). I am not sure how proceed after this step, the step of making the first letter uppercase.
    If anybody could help me out with this, it would be much appreciated.
    Thank you for all your help in advance.
    (PS I posted this thread earlier, but really didn't get much help. The one person posted a complete code, but that does not help me to understand(doesn't even work right!), and the others didn't give me insight as to if I was going to the right direction or how to proceed)

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    23
    I already said this at the end, but I really need help. I don't just want to use the other guy's code becuase I don't even understand how his works(I'm just a beginner at this), and the references you gave me to use were for c++, I need to write a C code. SO PLEASE if anybody could help with this, it would MUCH appreciated!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 09-23-2013, 02:59 AM
  2. Replies: 12
    Last Post: 11-24-2012, 04:10 AM
  3. Replies: 3
    Last Post: 10-12-2010, 01:40 PM
  4. make a char display a word or letter
    By dyelax in forum C++ Programming
    Replies: 12
    Last Post: 10-13-2009, 11:55 AM
  5. check if user input matches a word
    By fakebloo in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 07:12 PM