날마다 새롭게 또 날마다 새롭게

strcpy - 문자열 복사 함수 구현 코드 (문자열 배열, 포인터) 본문

프로그래밍/C / C++

strcpy - 문자열 복사 함수 구현 코드 (문자열 배열, 포인터)

아무유 2013. 3. 16. 00:20

/* strcpy : copy t to s; array subscript version */

void strcpy(char *s, char *t)

{

int i;

i=0;

while((s[i]=t[i]) != '\0')

i++;

}


/* strcpy : copy to s; pointer version 1 */

void strcpy(char *s, char *t)

{

while((*s=*t)!='\0') {

s++;

t++;

}

}


/* strcpy : copy to s; pointer version 2 */

void strcpy(char *s, char *t)

{

while((*s++ = *t++)!='\0')

}


/* strcpy : copy to s; pointer version 3 */

void strcpy(char *s, char *t)

{

while(*s++ = *t++)

;

}



Comments