K
Kayle
How should we check if the '\0' characters exists in the string as I am
confused that some books mentioned
that we have to check whether we need to make sure that we pass the
'null-terminated-string' to some functions,
such as 'atoi'. (We assume that the string was extracted using an array, not
string literal)
This program shows blank for '\0' for all 3 cases. Why ? And I was trying to
pass some strings formed using an array, without
appending '\0' and it worked. Was there any inconsistencies here?
char *str = "Hello"; // Case1
char str[] = {'H', 'e', 'l', 'l', 'o'}; // Case2
char str[] = {'H', 'e', 'l', 'l', 'o'}; // Case3
int length = strlen(str);
char *p;
int i;
// Testing whether '0' exists in the string
for (p = str, i = 0; i <= length; p++, i++) {
printf("Character %d is: %c\n",i,*p);
}
Anybody can clarify this issue? Thanks
confused that some books mentioned
that we have to check whether we need to make sure that we pass the
'null-terminated-string' to some functions,
such as 'atoi'. (We assume that the string was extracted using an array, not
string literal)
This program shows blank for '\0' for all 3 cases. Why ? And I was trying to
pass some strings formed using an array, without
appending '\0' and it worked. Was there any inconsistencies here?
char *str = "Hello"; // Case1
char str[] = {'H', 'e', 'l', 'l', 'o'}; // Case2
char str[] = {'H', 'e', 'l', 'l', 'o'}; // Case3
int length = strlen(str);
char *p;
int i;
// Testing whether '0' exists in the string
for (p = str, i = 0; i <= length; p++, i++) {
printf("Character %d is: %c\n",i,*p);
}
Anybody can clarify this issue? Thanks