Having input from a user and making each word in the input on its own line. If it is

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlanXu5
    New Member
    • Feb 2014
    • 1

    Having input from a user and making each word in the input on its own line. If it is

    Read a sentence from the console. Break the sentence into words using the space character as a delimiter. Iterate over each word, if the word is a numeric value then print its value doubled, otherwise print out the word, with each output on its own line.

    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


    I am having trouble figuring out how to double the number in the input.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    If your word is 100, you have three char values. You would need to convert these chars into an int, double the int, and print the int. You would not change the int back into a word of three chars 200.

    The library function atoi converts a string to an int.

    Code:
    int y;
        y = atoi(your word);
    You need to include <stdlib.h>.

    All you need do is display 2* y.

    Comment

    Working...