윤성우 열혈강의 C 정리
[ C 열혈강의 ] 22장 연습문제 : 구조체와 사용자정의 자료형1
by 어린왕자1234
2022. 7. 8.
// [ 문제22 - 1 : 구조체의 정의 ]
// 문제1 :
// 이름 주민번호 급여를 입력하는 구조체 선언 및 입출력
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char name[20];
char pid[20];
int salary;
} Employee;
void inputData(Employee* ptr);
void outputData(Employee* ptr);
int main(void)
{
Employee person;
inputData(&person);
outputData(&person);
}
void inputData(Employee* ptr)
{
printf("이름 입력 :");
scanf_s("%s", ptr->name,20);
printf("주민번호 입력 :");
scanf_s("%s", ptr->pid,20);
printf("급여 입력 :");
scanf_s("%d", &(ptr->salary));
}
void outputData(Employee* ptr)
{
printf("이름 입력 : %s\n", ptr->name);
printf("이름 입력 : %s\n", ptr->pid);
printf("이름 입력 : %d\n", ptr->salary);
}
// [ 문제22 - 2 : 구조체 배열의 선언 ]
// 문제1 :
// 이름 주민번호 급여를 입력하는 구조체 배열 선언 및 입출력
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char name[20];
char pid[20];
int salary;
} Employee;
void inputData(Employee* ptr);
void outputData(Employee* ptr);
int main(void)
{
Employee person[3];
for (int i = 0; i < 3; i++)
{
inputData(&person[i]);
outputData(&person[i]);
}
}
void inputData(Employee* ptr)
{
printf("이름 입력 :");
scanf_s("%s", ptr->name,20);
printf("주민번호 입력 :");
scanf_s("%s", ptr->pid,20);
printf("급여 입력 :");
scanf_s("%d", &(ptr->salary));
}
void outputData(Employee* ptr)
{
printf("이름 입력 : %s\n", ptr->name);
printf("이름 입력 : %s\n", ptr->pid);
printf("이름 입력 : %d\n", ptr->salary);
}