08/11/12 08:32:46
>>610 ②
struct Point {
double x;
double y;
};
void input_point_p(struct Point *p){
printf("X:");
scanf("%lf", &p->x);
printf("Y:");
scanf("%lf", &p->y);
}
void print_v_p2(struct Point *p){
printf("%f %f\n", p->x, p->y);
}
int main(void){
struct Point *p; /* 構造体ポインタ変数 p */
int num, i;
printf("Input number of vector: ");
scanf("%d", &num);
for (i=0; i< num; i++) {
p = malloc(sizeof(struct Point)); /* malloc を使って領域確保 */
if( p == NULL ) {
printf( "memory cannot alloc!\n" );
exit( 1 );
}
input_point_p(p); /* 関数を使って要素を代入 */
print_v_p2(p); /* 関数を使って要素の表示 */
free(p); /* メモリの解放 */
}
return 0;
}