What is the difference between memcpy() and strcpy()? I tried to find it with the help of a program but both are giving the same output.
printf("%s",...) stops printing the data when null is encountered, so both the outputs are same.
The following code differentiates between strcpy and memcpy:
#include
#include
int main()
{
char s[5]={'s','a','\0','c','h'};
char p[5];
char t[5];
int i;
strcpy(p,s);
memcpy(t,s,5);
for(i=0;i<5;i++)
printf("%c",p[i]);
printf("\n");
for(i=0;i<5;i++)
printf("%c",t[i]);
return 0;
}