ccplusplus.com
Learn C, C++ Concepts
Tuesday, September 20, 2011
c program to copy one string to another using pointers
/******************************************************************** * File : copy-one-string-to-another-using-pointer.c * Author : Saurabh Gupta * Desc : Program to Copy one string to another using pointer. * Source : http://saurabhgupta0527.blogspot.com/ * Created : AM 07:27 20 September 2011 * Note : ********************************************************************/ #include
int main() { char acFirstString[80], bcSecondString[80]; char *pcFirst = NULL, *pcSecond = NULL; //make sure to make them NULL first int i = 0; printf("Enter the string to copy : "); scanf("%s", acFirstString); pcFirst = &acFirstString[0]; pcSecond = &bcSecondString[0]; while(*pcFirst!='\0'){ *pcSecond = *pcFirst; pcFirst++; pcSecond++; } *pcSecond='\0'; printf("\nCopied string is : "); puts(bcSecondString); return 0; } /* * * [sgupta@rhel55x86 c]$ gcc copy-one-string-to-another-using-pointer.c -o copy-one-string-to-another-using-pointer [sgupta@rhel55x86 c]$ ./copy-one-string-to-another-using-pointer Enter the string to copy : saurabh Copied string is : saurabh [sgupta@rhel55x86 c]$ */
1 comment:
Unknown
May 8, 2014 at 5:01 PM
thanx!! It Helped me for my project!!
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
thanx!! It Helped me for my project!!
ReplyDelete