String Arrays..

Discussion in 'C' started by noobcoder, Jul 17, 2011.

  1. noobcoder

    noobcoder New Member

    Joined:
    Jul 17, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi! Good day. Uhh..I'm still learning how to use C. I'd like to ask for help about storing arrays..
    here's how it goes..

    When I input a string/char I'd like to store it an array. E.G. "Hi" output will be H i. God. I'm having a hard time explaining this..

    I give another example...I input Hello World the output will be.. H e l l o W o r l d

    any help?:confused:
     
  2. poornaMoksha

    poornaMoksha New Member

    Joined:
    Jan 29, 2011
    Messages:
    150
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Software developer
    Location:
    India
    Follow these steps :

    - Declare a character array of (say) 50 bytes
    - use 'getchar()' or 'gets' to accept input.
    - Store the input in array.
    - Print the array (as required).
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Something like this maybe?
    Code:
    char *str="Hello world";
    for (int i=0; str[i]; i++)
    {
      putchar(str[i]);
      putchar(' ');
    }
    
     
  4. noobcoder

    noobcoder New Member

    Joined:
    Jul 17, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Okay thanks! Great help! :)
     
  5. noobcoder

    noobcoder New Member

    Joined:
    Jul 17, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    BTW, Is there a way to cast a number like from hex to decimal? or is it just for Int, Char, and etc?
     
  6. noobcoder

    noobcoder New Member

    Joined:
    Jul 17, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    NVM i got it. XD
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice