DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: help help

  1. #1
    Join Date
    Nov 2007
    Location
    Trinidad
    Posts
    5

    Question help help

    Hi Everyone,

    I am j4me.

    I am new to programming. Can someone assist me with these questions;
    1. How to manipulate a string case e.g

    if the user typed: tOdAy iS suNny. I would like to change this sentence to: Today Is Sunny.

    2. validation: I am using isdigit and isalpha but still having problems with them.

    Thanks in advance everyone for your assistance. I will truly appreciate it.

    oh, I am using C++
    Last edited by j4me; 11-23-2007 at 03:57 AM. Reason: I forgot to write the language

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    try tolower and toupper
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    Nov 2007
    Posts
    17
    try to use isupper islowwer & tolower and toupper to do this

  4. #4
    Join Date
    Nov 2007
    Location
    Trinidad
    Posts
    5

    changing case

    Hi

    Thanks for your reply.

    However, I am still not clear on the solution.

    I am able to input a sentence from any user and change the entire sentence into caps but I don't know how to change the first letter of every word into cap and then output the sentence.

    I am trying to creat a code to do this.

  5. #5
    Join Date
    Oct 2007
    Posts
    369
    Algorithm:
    Set startOfWord to true.
    Loop through each letter:
    - if a space, set startOfWord to true.
    - if not a space:
    -- if startOfWord is true, call toupper on the letter.
    -- if not startOfWord, call tolower on the letter.

  6. #6
    Join Date
    Nov 2007
    Location
    Trinidad
    Posts
    5

    thanks

    Thanks alot.
    I am going to try this out.

  7. #7
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    -- if startOfWord is true, call toupper on the letter, set startOfWord to false.
    -- else if not startOfWord, call tolower on the letter.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  8. #8
    Join Date
    Oct 2007
    Posts
    369
    I could say that I left that for j4me to figure out. But, alas, Amahdy caught me.
    It was my one mistake for the day.

  9. #9
    Join Date
    Nov 2007
    Location
    Trinidad
    Posts
    5
    Hi everyone

    Does anyone have any simple idea how to generate the periodic table in Cpp?

  10. #10
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Chemistry periodic table did you mean ?
    There is no constant function that can make this, and I don't think you can do that without inline coding ... or what did you meant exactly ??
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  11. #11
    Join Date
    Nov 2007
    Location
    Trinidad
    Posts
    5

    Chemistry Periodic table

    Well, I was trying to find a shorter way of writing it in cpp. Anyway, I am finish coding it.

  12. #12
    Join Date
    Nov 2007
    Posts
    17
    Quote Originally Posted by j4me
    Hi Everyone,

    I am j4me.

    I am new to programming. Can someone assist me with these questions;
    1. How to manipulate a string case e.g

    if the user typed: tOdAy iS suNny. I would like to change this sentence to: Today Is Sunny.

    2. validation: I am using isdigit and isalpha but still having problems with them.

    Thanks in advance everyone for your assistance. I will truly appreciate it.

    oh, I am using C++

    try this it may slove ur issue.

    void main()
    {
    char name[14]="tOdAy iS suNny";
    char prev = " ";
    char next;
    int i=0;
    cout<<name<<endl;
    while(name[i])
    {
    if(prev == " " && islower(name[i]))
    name[i]=toupper(name[i]);
    else
    {
    if(isupper(name[i]))
    name[i]=tolower(name[i]);
    }
    prev=name[i];
    i++;
    }
    cout<<name<<endl;


    }

  13. #13
    Join Date
    Nov 2003
    Posts
    4,118
    This declaration will not compile:

    char prev = " ";

    You're declaring a single char, but initializing it with array of two chars: the space and the nul. Better use
    char prev= '\b';
    Danny Kalev

  14. #14
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Actually there is some compilers who just generate a warning and ignore it,, by just adjusting it like if it was : char prev=' ';
    Danny is right, you should not use it like that to not get such error :
    Code:
    if(prev == " " && islower(name[i]))
    this if condition will be for ever FALSE as Danny said, prev is char, and a char can never be equal to 2 char .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  15. #15
    Join Date
    Nov 2007
    Posts
    17
    Quote Originally Posted by Amahdy
    Actually there is some compilers who just generate a warning and ignore it,, by just adjusting it like if it was : char prev=' ';
    Danny is right, you should not use it like that to not get such error :
    Code:
    if(prev == " " && islower(name[i]))
    this if condition will be for ever FALSE as Danny said, prev is char, and a char can never be equal to 2 char .
    use function

    int isspace( int ch );


    The isspace() function returns non-zero if its argument is some sort of space (i.e. single space, tab, vertical tab, form feed, carriage return, or newline). Otherwise, zero is returned

    which slove ur issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center