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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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"
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
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
ASKER