I've been told the null character or '\0'
serves a purpose to identify the end of a string.
But, I'm in a haze as I have come across two programs thus far, in which, there have been no usage of the same(null character).
All three programs deal with strlen()
, and I cannot extrapolate its significance and/or presence in this one.
char st[20], rst [20]; // Edit: Added these string declarations!
int i, j;
printf("\n Enter the string : ");
scanf("%s",st);
i= 0;
j = strlen(st) - 1;
while (j >= 0)
{
rst[i] = st[j];
i++;
j--;
}
rst[i] = '\0';
if(strcmp(st, rst) == 0)
printf("\n %s is a palindrome string", st);
else
printf("\n %s is not a palindrome string", st);
And it appears like the inclusion or exclusion of the null character does not affect the result.
But, I'm curious why the author may find it imperative to add it.