[[프로그래밍_NOTE]]/C , C++

strcpy 기능 구현

갑빠돌격기 2008. 8. 13. 13:19

/**** 기존 strcpy()의 기본적인 사용법 ***********************
   #include<stdio.h>
   #include<string.h>
   void main()
   {
    const char temp1[8] = {"홍길동"};
    char temp2[8];

    strcpy(temp2,temp1);
    printf("temp1->%s\n",temp1);
    printf("temp2->%s\n",temp2);
   }
*********************************************************/

/***** MyStrCpy의 구현 ***********************************
#include<stdio.h>

void MyStrCpy(char* pDest_Str , const char* pSource_Str)
{
    while(*pSource_Str)
   {
      *pDest_Str = *pSource_Str;
     ++pSource_Str;
      ++pDest_Str;
   }
   *pDest_Str=NULL;
}

void main()
{
    const char temp1[8] = {"홍길동"};
    char temp2[8];
 
    MyStrCpy(temp2,temp1);
    printf("temp1->%s\n",temp1);
    printf("temp2->%s\n",temp2);
}
**********************************************************/
result)

사용자 삽입 이미지