Thread: Capitalization help

  1. #1
    Unregistered
    Guest

    Capitalization help

    Ok, I need to write a program that capitalizes the first letters of a given sentance.
    I am completely lost doing this.
    I just need a kick in the right direction if someone could help.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    if you want to just capitalise the first letter of the sentence then do this:

    Code:
    #include <ctype.h>
    
    void Capitalize(char* sentence)
    {
       if(sentence && strlen(sentence) > 0)
      {
        sentence[0] = toupper(sentence[0]);
      }
    }
    if you need to do the first letter of every word in the sentence then do this:

    Code:
    #include <ctype.h>
    
    void Capitalize(char* sentence)
    {
       int i = 0;
       int length;
    
       if(sentence && strlen(sentence) > 0)
      {
        length = strlen(sentence);
        while(i < length)
        {
            if(sentence[i] == ' ' && i < length - 1)
            {
                sentence[i + 1] = toupper(sentence[i + 1]);
            }
            i++;
        }
      }
    }
    hope this helps!
    U.
    Last edited by Uraldor; 12-20-2001 at 12:44 AM.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program can't locate resource when run outside IDE
    By IdioticCreation in forum C++ Programming
    Replies: 10
    Last Post: 03-31-2009, 09:41 PM
  2. Capitilization in titles
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-24-2004, 12:52 PM
  3. capitalization trick
    By volk in forum C++ Programming
    Replies: 11
    Last Post: 04-05-2003, 07:12 PM