Hi,
Simply I'm tried to compile this code which is printing as what's shown in the printf .. I don't know it's displaying me on screen wrong results and don't know what's the logic Error in the code to fix it.
Code:
int main()
{
char source[10], *des = strcpy(source, "012345678");
printf("%d\n", sizeof(des));// didn't understand why it's giving me 8 instead of 9?! I'm having a pointer to string "012345678", pointer to string is also string!
char *dest = (char *)malloc(strlen(source) + 1); // +1 for nill value, right?! I reckon on that.
for (int i = 1; i <= strlen(source);i++)
dest[i] = source[i];
dest[strlen(source) + 1] = '\0';
printf("dest = %s", dest); // I dont know what's the wrong here its printing me "12345678" and "not 012345678" !!!
}
thanks for your help!