char cstri[] = "hello world";
From here, is there any way to get a single char, such as the first e
, position at 1, from this cstring?
I tried a few times, and every time it returns the entire string starting from the passed index. So, if I want 'e', position at 1, it returns ello world
instead of just e
.
I also tried to copy a single char from the string using strncpy()
and memcpy()
, but it copies the string from index 0 to null, or just the specified amount.
strncpy(b, cstri , 1);
I know a cstring is read-only, but is there no way to get a single char from a cstring?
I want to use printf()
, so I can't use char b = cstri[1]