I am trying to change the value referred to by a character pointer to a character type variable after initializing it to a string literal.
In the output, the character 'L', which should be the only character printed, is followed by some random characters, which I think are garbage values.Code:#include <stdio.h> void func7() { char c = 'L'; char *p = "APPLES"; p = &c; printf("%s\n", p); }
I thought it was because the printf function kept printing characters until it encountered '\0' character, so I added this line
but its giving run time error, so I used string functionCode:*(p + 1) = '\0';
but even after this I am getting the same output.Code:strcat(p, "\0");
Is this because %s is causing some error, or my character pointer is not pointing to a string or something else?