Help w/isupper function

This is a discussion on Help w/isupper function within the C++ Programming forums, part of the General Programming Boards category; I have this program that I need to write in a name.....for example "Richard Michael Smith" and output just their ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Question Help w/isupper function

    I have this program that I need to write in a name.....for example "Richard Michael Smith" and output just their initials. I can't figure out how to output just the initials.
    I have
    cout << "Enter in your name " ;
    getline(cin,name);

    then i'm thinking
    if (isupper.... ?

    i don't know how to only count the single initials from a string as a char like isupper checks only a single character at a time.

    If someone could help me on this one, I would really appreciate it.

    Thanks,
    Nick

  2. #2
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    You could make an array of characters, and the initials will be the first char followed by the letters after spaces. (sorry I don't feel like writing code)

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    You need to read in the name as a string, then parse each part of the name out using strtok(). Once you have each token then just use the first character of each token and you have your intials. If you need example code post again. (if someone else doesn't post it)

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    sample code????

    Yeah, could you give some example code for it? I would appreciate it. Thanks

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: sample code????

    Originally posted by Nicholas35
    Yeah, could you give some example code for it? I would appreciate it. Thanks
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin;
    #include <cstring>
    
    
    int main(int argc, char *argv[])
    {
    char input[255],*token = 0;
    cout << "Enter your name" << endl;
    cin.getline(input,254);
    token = strtok(input," ");
    
    do{
    cout << token[0] << " ";
    token = strtok(NULL," ");
    }while(token);
      return 0;
    }
    Try that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 11:08 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21