Consider the following code, which works fine asusual for copying string
#include<stdio.h>
void strcp(char *s1, char *s2);
int main() {
char s1[]="Hai, I am a good boy"; //1
char s2[]="Really I am a good boy"; //2
strcp(s1,s2);
printf("%s",s1);
return 0;
}
void strcp(char *s1, char *s2) {
while(*s1++=*s2++);
}
What changes I have to made if I want to declare s1, s2
as pointers to char inside main()
?
char *s1="Hai, I am a good boy"; //1
char *s2="Really I am a good boy"; //2
I tried to copy pointer values as shown below
void strcp(char *s1, char *s2) {
s1=s2;
}
But it didn't work.