0
strncat의 내 버전이 너무 많은 문자를 대상에 복사하고 있는데 그 이유를 알 수 없습니다. 'N'이 너무 많은 문자이다하나의 오류로 인해 strncat이 해제되었습니다. - K & R C 연습 5-5
stringy
를 출력으로 사용 3
#include <stdio.h>
#define MAX_CHARS 20
void nconcatenate(char *start, char *end, int n)
{
if(sizeof start + n > MAX_CHARS)
return;
while(*start++);
start--; /* now points to the final char of start, the \0 */
int i;
for(i = 0; (*start++ = *end++) && i < n; i++);
*start = '\0';
}
int main()
{
char start[MAX_CHARS] = "str";
char *end = "ingy!";
nconcatenate(start, end, 3);
printf("start = %s\n", start);
return 0;
}
.
디버거에서 코드를 밟아 보셨습니까? – OldProgrammer
'sizeof start'는 항상'sizeof (char *)'btw를 반환합니다. –
@OldProgrammer 나는 아직 많이 사용하는 초보자이지만 gdb로 시도했다. –