I am currently writing a program where i was stuck in a different kind of behaviour of strcpy() function . Here is short demo of it...
I went through the following question : Strip first and last character from C string
//This program checks whether strcpy() is needed or not after doing the modification in the string
#include <stdio.h>
#include <string.h>
int main()
{
char mystr[] = "Nmy stringP";
char *p = mystr ;
p++;
p[strlen(p)-1] = '\0';
strcpy(mystr,p);
printf("p : %s mystr: %s\n",p,mystr);
}
Output :-
p : y strnng mystr: my strnng
If i dont use strcpy() function , then i get
p : my string mystr : Nmy string
Why is this happening ??