I understand that string ends with a NULL. But if there is a null character(\0) in the middle of string, how can I handle the string?
#include<stdio.h>
#include<string.h>
int main(){
char *str = "App\0le";
char *str2;
printf("%c", *(str+5));
}
output: e
- string is ends with null character(\0), how can "e" be output?
- Without function in <string.h>, how can i assign apple using str1?
You can't have a null character in the middle of a C string, because a null character, by definition, ends the string.
You can use arrays of chars where some of them are null characters, but you have to treat them as arrays, not strings. So you have to keep track of the length yourself.