일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- html5 new tag
- html youtube
- #binary
- html code
- #bubbleSort
- #JAVASCRIPT
- docker example
- #C++ has~a
- git flow
- hyperledger transaction
- html video
- 토큰경제
- html object
- html charset
- #자바상속#자바이즈어#is~a
- relative path
- #3차원배열
- 하이퍼레저패브릭
- border-box
- #다차원포인터
- #1차원배열
- html id
- html multimedia
- mac terminal command
- html plug-in
- #android activity
- #2차원배열
- #성적관리프로그램
- #C++ 연산자함수오버로딩
- #CallByAddress
- Today
- Total
A sentimental robot
다차원포인터 활용 본문
#include<stdio.h>
#pragma warning(disable:4996);
#include<stdlib.h>
void input(char (*name)[10],int (*score)[4]) // == char name[][10], int score[][4]
{
int i,j;
for(j=0 ; j<3 ; j++){
printf("name input:");
scanf("%s",name[j]);
for(i=0 ; i<3 ; i++){
printf("score input:");
scanf("%d",score[j]+i);
}
}
}
void oper(int (*score)[4], float *avg)
{
int i,j;
for(j=0 ; j<3 ; j++){
for(i=0 ; i<3 ; i++){
*(score[j]+3)+=*(score[j]+i);
}
*(avg+j) = *(score[j]+3)/3.f;
}
}
void output(char (*name)[10],int (*score)[4], float*avg)
{
int i,j;
system("cls");
for(j=0 ; j<3 ; j++){
printf("%s\t",name[j]);
for(i=0 ; i<4 ; i++){
printf("%d\t",*(score[j]+i));
}
printf("%f\n",*(avg+j));
}
}
void main(){
char name[3][10];
int score[3][4] = {0,};
float avg[3];
input(name,score);
oper(score,avg);
output(name,score,avg);
}
#include<stdio.h>
#pragma warning(disable:4996);
void connect(int ***ppp, int **pp, int *a, int *b, int *c)
{
*ppp = pp;
(*ppp)[0] = a;
(*ppp)[1] = b;
(*ppp)[2] = c;
}
void input(int **pp)
{
int i;
for (i = 0; i<3 ; i++)
{
printf("a,b,c input:");
scanf("%d", *(pp+i));
}
}
void disp(int **pp)
{
int i;
for (i = 0; i<3 ; i++)
{
printf("%d\t", **(pp+i));
}
}
void main()
{
int a = 10, b = 20, c = 30;
int *p[3];
int **pp;
connect(&pp, p, &a, &b, &c);
input(pp);
disp(pp);
}
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996);
void memalloc(char (**name)[10],int (**score)[4],float **avg,int *num)
{
*name = (char (*)[10])calloc(*num,sizeof(int)*10);
*score = (int (*)[4])calloc(*num,sizeof(int)*4);
*avg = (float *)calloc(*num,sizeof(int));
}
void input(char (*name)[10],int (*score)[4],float *avg,int *num)
{
int i,j;
for(j=0 ; j<*num ; j++)
{
printf("Name input :");
scanf("%s",name+j);
printf("Score input :(국,영,수순으로 입력 )");
for(i=0 ; i<3 ; i++)
{
scanf("%d",*(score+j)+i);
*(*(score+j)+3) += *(*(score+j)+i) ;
}
*(avg +j)= *(*(score+j)+3)/3.f;
}
}
void disp(char (*name)[10],int (*score)[4],float *avg,int *num)
{
int i,j;
for(j=0 ; j<*num ; j++)
{
printf("Name = %s\n",name+j);
for(i=0 ; i<4 ; i++)
{
printf("%d\t",*(*(score+j)+i));
}
printf("%.2f\n",*(avg+j));
}
}
void del(char (*name)[10],int (*score)[4],float *avg)
{
free(name);
free(score);
free(avg);
}
void main()
{
int num;
char (*name)[10] = NULL;
int (*score)[4] = NULL;
float *avg = NULL;
printf("how many students?");
scanf("%d",&num);
memalloc(&name,&score,&avg,&num);
input(name,score,avg,&num);
disp(name,score,avg,&num);
del(name,score,avg);
}
'C ' 카테고리의 다른 글
strlen함수 만들기 (0) | 2018.01.02 |
---|---|
2차원배열 동적할당 (0) | 2018.01.02 |
Call by address (0) | 2018.01.02 |
문자열 비교함수 (0) | 2018.01.02 |
문자열 (0) | 2018.01.02 |