Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   String Arrays.. (http://www.go4expert.com/forums/string-arrays-t26295/)

noobcoder 17Jul2011 15:39

String Arrays..
 
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:

poornaMoksha 18Jul2011 17:40

Re: String Arrays..
 
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).

xpi0t0s 19Jul2011 12:16

Re: String Arrays..
 
Something like this maybe?
Code:

char *str="Hello world";
for (int i=0; str[i]; i++)
{
  putchar(str[i]);
  putchar(' ');
}


noobcoder 19Jul2011 18:17

Re: String Arrays..
 
Okay thanks! Great help! :)

noobcoder 19Jul2011 18:23

Re: String Arrays..
 
BTW, Is there a way to cast a number like from hex to decimal? or is it just for Int, Char, and etc?

noobcoder 19Jul2011 18:28

Re: String Arrays..
 
NVM i got it. XD


All times are GMT +5.5. The time now is 16:27.