Ouput In String In Uppercase

This is a discussion on Ouput In String In Uppercase within the C Programming forums, part of the General Programming Boards category; Code: I have a program that takes in a string of less than 80 characters from keyboard. AND it will ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Post Ouput In String In Uppercase

    Code:
    I have a program that takes in a string of less than 80 characters  from keyboard. 
    AND it will convert all alphabets into UPPERCASE.
    
    But I do not know how to exclude numbers, punctuations, hyphens, spaces, symbols etc. when displaying.
    
    for the time being my program is this:
    
    #include <stdio.h> 
    #include <ctype.h> 
    
    void upstr(char *s)
    {
      char  *p;
    
      for (p = s; *p != '\0'; p++) 
        *p = (char) toupper(*p);
    }
    
    int main(void)
    {
      char  mystring[] = "strawberry cake!";
      puts(mystring);
      upstr(mystring);
      puts(mystring);
      return(0);
    
    }
    
    how do i exclude this punctuations and spaces???
    i need HELP!!!

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    http://www.cplusplus.com/reference/clibrary/cctype/

    switch/if statement and check the truth of these functions.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Look up the functions in ctype.h. You can do this multiple ways by comparing against what you want to keep vs comparing against what you want to exclude.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You'll need an extra pointer -- one for where you're reading from, one for where you're reading to. If the char you get from toupper does not satisfy isupper, then it's not a letter.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    how do u exclude those space, comas those symbols?

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    R
    T
    M


    Try google for ctype.h. You might have found this website.

  7. #7
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    If the functions come back true just ++ your pointer or array indice. Like you are doing in your example in the for loop.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lowqiumei View Post
    how do u exclude those space, comas those symbols?
    Did you read tabstops post? It is clear you didn't understand it, so perhaps you can ask a better question in relation to the post by tabstop - it does imply how to do that task?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 12:40 PM

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