I was practicing in C gcc compiler for Strings and I got the below confusion between strlen and strcopy please tell me what kind of behavior it is? When I run my below Program without using Strlen function:
#include <stdio.h>
int main()
{
int k;
char p[5];
char p1[10];
printf("Enter String in p");
gets(p);
printf("String is %s\n",p);
strcpy(p1,p);
puts(p1);
puts(p);
return 0;
}
output:
Enter String in pshadab qureshi
String is shadab qureshi
shadab qureshi
eshi
and When I Run Program Using Strlen Function like:
#include <stdio.h>
int main()
{
int k;
char p[5];
char p1[10];
printf("Enter String in p");
gets(p);
printf("String is %s\n",p);
k=strlen(p);
strcpy(p1,p);
puts(p1);
puts(p);
return 0;
}
Then the output is:
Enter String in pshadab qureshi
String is shadab qureshi
shada
shada
please explain me the behavior why is this happening?