String Arrays..

Newbie Member
17Jul2011,15:39   #1
noobcoder's Avatar
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?
Ambitious contributor
18Jul2011,17:40   #2
poornaMoksha's Avatar
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).
Mentor
19Jul2011,12:16   #3
xpi0t0s's Avatar
Something like this maybe?
Code:
char *str="Hello world";
for (int i=0; str[i]; i++)
{
  putchar(str[i]);
  putchar(' ');
}
Newbie Member
19Jul2011,18:17   #4
noobcoder's Avatar
Okay thanks! Great help!
Newbie Member
19Jul2011,18:23   #5
noobcoder's Avatar
BTW, Is there a way to cast a number like from hex to decimal? or is it just for Int, Char, and etc?
Newbie Member
19Jul2011,18:28   #6
noobcoder's Avatar
NVM i got it. XD