일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- html youtube
- html object
- 하이퍼레저패브릭
- hyperledger transaction
- mac terminal command
- html video
- #2차원배열
- html5 new tag
- html charset
- #C++ 연산자함수오버로딩
- border-box
- 토큰경제
- html id
- #3차원배열
- #자바상속#자바이즈어#is~a
- relative path
- docker example
- #성적관리프로그램
- html multimedia
- git flow
- #1차원배열
- #다차원포인터
- html plug-in
- #binary
- #CallByAddress
- html code
- #C++ has~a
- #JAVASCRIPT
- #android activity
- #bubbleSort
- Today
- Total
A sentimental robot
구조체 동적메모리 본문
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
struct score
{
char name[10];
int kor;
int eng;
int mat;
int total;
float avg;
};
void main()
{
struct score *p;
int num, i;
printf("How many students?");
scanf("%d", &num);
p = (struct score*)calloc(num, sizeof(struct score));
for (i = 0; i < num; i++)
{
printf("name input:");
scanf("%s", (p + i)->name);
printf("kor input:");
scanf("%d", &(p + i)->kor);
printf("eng input:");
scanf("%d", &(p + i)->eng);
printf("mat input:");
scanf("%d", &(p + i)->mat);
(p + i)->total = (p + i)->kor + (p + i)->eng + (p + i)->mat;
(p + i)->avg = (p + i)->total / 3.f;
}
for (i = 0; i < num; i++)
{
printf("%s\t", (*(p + i)).name);
printf("%d\t", (*(p + i)).kor);
printf("%d\t", (*(p + i)).eng);
printf("%d\t", (*(p + i)).mat);
printf("%d\t", (*(p + i)).total);
printf("%f\n", (*(p + i)).avg);
}
free(p);
}
#include<stdio.h>
#include<stdlib.h>
#pragma warning (disable:4996)
struct a {
char name[10];
int kor;
int eng;
int mat;
int total;
float avg;
};
void main()
{
struct a * pa;
int num, i;
printf("how many?");
scanf("%d", &num);
pa = (struct a*)malloc(sizeof(struct a)*num);
for (i = 0; i < num; i++) {
printf("name :");
scanf("%s", pa[i].name);
printf("kor :");
scanf("%d", &pa[i].kor);
printf("eng :");
scanf("%d", &pa[i].eng);
printf("mat :");
scanf("%d", &pa[i].mat);
pa[i].total = pa[i].kor + pa[i].eng + pa[i].mat;
pa[i].avg = pa[i].total / 3.f;
}
for (i = 0; i < num; i++) {
printf("%s %d %d %d %d %f\n", pa[i].name, pa[i].kor, pa[i].eng, pa[i].mat, pa[i].total, pa[i].avg);
}
free(pa);
}