| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- c언어 최대최소
- 비주얼 스튜디오 다운로드
- C언어 달력
- 메이플스토리
- c언어 버블정렬
- c샾 헬로우 월드
- N Queen 문제
- 온라인 비주얼 스튜디오
- c언어 배열 programming
- LUA
- c sharp hello world
- c언어 콘서트 배열
- c#온라인
- N Queen Coordinates
- N Queens Problem
- c++ 등차수열 합
- Lua language
- 비주얼 스튜디오
- lua 다운로드
- lua download
- c샾 hello world
- 루아다운로드
- 유니티
- for문
- Lua 설명
- 루아
- Lua란
- c언어 콘서트 배열 2번
- 게임제작
- 2중 반복문
Archives
- Today
- Total
Ln Go
구조체 공용체 본문
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct date {
int year;
int month;
int day;
};
typedef struct date date;
struct fruit {
char name[20]; //과일이름 name(문자열),
int price; //가격 price(정수)
date expire; //만기일 expire(1번의 date 타입)
char throw; //폐기여부 throw(‘y’ 또는 ‘n’)
};
typedef struct fruit fruit;
void ex_08() {
fruit store[5] = {
"apple", 500, 2020, 9, 1, 'n',
"banana", 500, 2020, 7, 3, 'n',
"orange", 500, 2022, 3, 31, 'n',
"melon", 500, 2021, 11, 11, 'n',
"mango", 500, 2021, 5, 30, 'n'
};
fruit *p;
int size = sizeof(store)/sizeof(store[0]);
int sum = 0;
p=store;
for(int i=0; i<size; i++) {
printf("%d) name=%s, price=%d, year=%d, month=%d, day=%d, throw=%c\n",
i, (p+i)->name, (p+i)->price, (p+i)->expire.year, (p+i)->expire.month, (p+i)->expire.day, (p+i)->throw);
}
time_t now = time(NULL);
struct tm *today = localtime(&now);
printf("\n오늘의 날짜 : %d년 %d월 %d일 \n\n",
today->tm_year+1900, today->tm_mon+1, today->tm_mday);
char day[10] = {'\0', };
sprintf(day, "%04d%02d%02d", today->tm_year+1900, today->tm_mon+1, today->tm_mday);
for(int i=0; i<size; i++) {
char exp[10] = {'\0', };
sprintf(exp, "%04d%02d%02d", (p+i)->expire.year, (p+i)->expire.month, (p+i)->expire.day);
if(atoi(exp) <= atoi(day))
{
(p+i)->throw = 'y';
sum += (p+i) -> price;
}
}
printf("폐기가격 총합 : %d \n",sum);
for(int i=0; i<size; i++) {
printf("%d) name=%s, price=%d, year=%d, month=%d, day=%d, throw=%c\n",
i, (p+i)->name, (p+i)->price, (p+i)->expire.year, (p+i)->expire.month, (p+i)->expire.day, (p+i)->throw);
}
}
int main(int argc, char *argv[]) {
ex_08();
return 0;
}'C언어' 카테고리의 다른 글
| 비쥬얼 스튜디오 코드 정리 단축키 변경 (0) | 2021.06.05 |
|---|---|
| c언어 최대 최소 (0) | 2021.05.26 |
| N Queen 좌표 출력 (0) | 2021.05.23 |
| c언어 콘서트 배열 programming p292 2번 (0) | 2020.04.13 |
| c언어 콘서트 배열 programming p292 1번 (0) | 2020.04.13 |
Comments