336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

개념 : 


malloc 이나 calloc 된 공간을 재 할당  할때 사용합니다.




소스코드 : main.c

#include <stdio.h>

#include <string.h>

#include <malloc.h>


int main(void)

{

char *pString = "Hello JunmoZzi";

char *pAdd = " ^^a ha ha ha!";


char *pBuffer = NULL;

int nSize1 = strlen(pString) + 1;

int nSize2 = strlen(pAdd) + 1;

pBuffer = calloc(nSize1 + 1, sizeof(char));


if (pBuffer == NULL)

{

puts("memory 할당 실패");

}

else

{

puts("memory 할당 성공");

printf("메모리 주소 : %d\n", pBuffer);

strcpy_s(pBuffer, nSize1, pString);

}


puts(pBuffer);

puts("메모리 재 할당");


realloc(pBuffer, nSize1 + nSize2);


strcat_s(pBuffer, nSize1 + nSize2, pAdd);

printf("메모리 주소 : %d\n", pBuffer);

puts(pBuffer);


free(pBuffer);

pBuffer = NULL;

return 0;

}



결과



#realloc,#c언어, #c언어입문, #프로그램입문, #realloc, #메모리재할당


+ Recent posts