C

[C] 124 구조체 배열을 함수에서 사용하기

qkrwngus 2021. 1. 29. 20:13

Desc :

 

 


Source Code :

#include <stdio.h>
#include <string.h>

struct tagStaff
{
	char name[10];
	char phone[20];
	char address[100];
};

void print(struct tagStaff *pstaff);

void main()
{
	struct tagStaff staff[3];
	int i;

	for (i = 0; i < 3; i++)
	{
		sprintf(staff[i].name, "홍길동 %d", i);
		sprintf(staff[i].phone, "010-1234-456%d", i);
		sprintf(staff[i].address, "서울시 강남구 %d단지", i);
	}

	print(staff);
}

void print(struct tagStaff *pstaff)
{
	int i;

	for (i = 0; i < 3; i++)
	{
		printf("이름: %s\n", pstaff[i].name);
		printf("전화번호: %s\n", pstaff[i].phone);
		printf("주소: %s\n", pstaff[i].address);
	}
}

 


Result :