Dear all
I'm new here and also new to C language. I have been stuck with string problem in C for some time and I decide to post here to get some help, please kindly explain what I get wrong with the code
char *ptr, *old2, *oldstring);
printf("\nEnter oldstring expression :");
gets(oldstring) ;
printf("\n%s : old2", old2);
ptr = strcpy(old2, oldstring);
printf("\n%s : old2", ptr);
printf("\n%s : old2", old2);
Seems like when I entered oldstring, the program tends to freeze, I assume the problem is "segmentati on error" but I'm not sure.. Please anyone tell me how to copy the value of string to another string, I have used
a = oldstring;
provided a and oldstring is char*
a value tend to change even after that I change value of oldstring.. I think it's because a is just a pointer isn't it?
Thank you very much for all answers
I'm new here and also new to C language. I have been stuck with string problem in C for some time and I decide to post here to get some help, please kindly explain what I get wrong with the code
char *ptr, *old2, *oldstring);
printf("\nEnter oldstring expression :");
gets(oldstring) ;
printf("\n%s : old2", old2);
ptr = strcpy(old2, oldstring);
printf("\n%s : old2", ptr);
printf("\n%s : old2", old2);
Seems like when I entered oldstring, the program tends to freeze, I assume the problem is "segmentati on error" but I'm not sure.. Please anyone tell me how to copy the value of string to another string, I have used
a = oldstring;
provided a and oldstring is char*
a value tend to change even after that I change value of oldstring.. I think it's because a is just a pointer isn't it?
Thank you very much for all answers
Comment