typedef struct _tagTestStruct {
    int x;
    int y;
} testStruct;

void AddStructure(testStruct structArray[], int *count)
{
    testStruct sample;

    memset(&sample, 0x00, sizeof(testStruct));
    sample.x = 5;
    sample.y = 50;

    memcpy(&structArray[*count], &sample, sizeof(testStruct));
    (*count)++;
}

int main(void)
{
    int cnt=0, i;
    testStruct structArr[4];

    memset(&structArr, 0x00, sizeof(structArr));
    for(cnt=0; cnt<2; cnt++)
    {
        structArr[cnt].x = cnt+1;
        structArr[cnt].y = cnt+10;
    }

    AddStructure(structArr, &cnt);

    for(i=0; i<cnt; i++)
    {
        printf("structArr[%d] x=[%2d] y=[%2d]\n", i, structArr[i].x, structArr[i].y);
    }
}

'c' 카테고리의 다른 글

리눅스 IP충돌 체크  (0) 2022.09.08
리눅스 정규식을 이용한 IP / Email 주소 체크  (0) 2022.09.06
리눅스 usb mount 예제  (0) 2021.07.20
ASCII & 한글 완성형(KSC5601) 출력 소스  (0) 2021.07.08
C관련Etc...  (0) 2021.06.17
Posted by afewgood
,