본문 바로가기

Native/C

malloc

[code]#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    char **p;
    int i;
    p = (char **)malloc(sizeof(char *)*2);
    for (i=0; i<2; ++i)
    {
        p[i] = (char *) malloc(10);
        memset(p[i], 0, 10);
        scanf("%s", p[i]);
    }

    for (i=0; i<2; ++i)
    {
        printf("%s\n", *(p+i));
        free(*(p+i));
    }
    free(p);
    
    return 0;
}
[/code]

'Native > C' 카테고리의 다른 글

정의 상수  (0) 2013.10.02
point  (0) 2013.10.02
더블 포인터 예제  (0) 2013.10.02
파일처리  (0) 2013.10.02
getc()  (0) 2013.10.02