반응형
Q>
전화번호부와 같이 구조체를 정의하여 관리 및 검색을 하면 더 편리한 예는 또 무엇이 있을까요?
A>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
struct Company
{
int no;
char name[10];
char id[10];
char division[50];
};
int main(void)
{
struct Company employee1;
struct Company employee2;
employee1.no = 12345;
strcpy(employee1.name, "Ankiwoong");
strcpy(employee1.id, "ankw");
strcpy(employee1.division, "contract worker");
employee2.no = 23456;
strcpy(employee2.name, "Kimyurim");
strcpy(employee2.id, "kiyu");
strcpy(employee2.division, "staff");
printf("Employee1's employee number is %d.\n", employee1.no);
printf("Employee1 is named %s.\n", employee1.name);
printf("Employee1's account ID is %s.\n", employee1.id);
printf("Employee1 is in %s.\n", employee1.division);
printf("\n");
printf("Employee2's employee number is %d.\n", employee2.no);
printf("Employee2 is named %s.\n", employee2.name);
printf("Employee2's account ID is %s.\n", employee2.id);
printf("Employee2 is in %s.\n", employee2.division);
}
https://www.boostcourse.org/cs112
반응형
'C > 부스트코스' 카테고리의 다른 글
[부스트코스]알고리즘 퀴즈 5 (0) | 2021.01.30 |
---|---|
[부스트코스]알고리즘 퀴즈 4 (0) | 2021.01.29 |
[부스트코스]알고리즘 퀴즈 2 (0) | 2021.01.28 |
[부스트코스]알고리즘 퀴즈 1 (0) | 2021.01.28 |
[부스트코스]C 언어 배열 9 (0) | 2021.01.27 |