Link to home
Start Free TrialLog in
Avatar of cfans
cfans

asked on

Indexing Char *

Say i've got:
char * word = "hello";

how do I index through hello.

I wanted to use a for loop going through the word one character at a time.
I thought that word[0] would give me "o" but it gives the whole thing "hello".
So i'm not sure how to index through.
Avatar of cfans
cfans

ASKER

The reason I'm indexing in is to then change a letter within it.
ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cfans

ASKER

Ike, thanks.. I can't seem to get change an entry in it.. have any idea how to change.. like 'h' to 's'
to ultimately make the work then "sello"
tdeclare your strings this way:

char word[] = "hello";

word[1] = 'x';

but this is a static-sized string, don't put more than 5 letters in it!!
otherwise use dynamically allocated arrays ...

ike