프로그래밍
구조체 화살표 연산자로 데이터 항목 참조하기
Dilrong
2013. 10. 8. 14:00
//화살표 연산자로 데이터 항목 참조하기
#include<stdio.h>
#include<string.h>
//구조체 정의
struct employee{
char name[10];
int year;
int pay;
};
void main()
{
//구조체 선언
struct employee Lee;
struct employee *Sptr = &Lee;
//문자열 복사(초기화 할때가 아니면 strcpy 필요)
strcpy(Sptr->name, "이순신");
//포인터로 참조함 .은 변수로
Sptr->year = 2500;
Sptr->pay = 2900;
//구조체 변수 출력
printf("\n 이름 : %s", Sptr->name);
printf("\n 입사 : %d", Sptr->year);
printf("\n 연봉 : %d", Sptr->pay);
getchar();
}
반응형