1 动态结构体
1 #define _CRT_SECURE_NO_WARNINGS 2 3 #include<stdio.h> 4 #include<stdlib.h> 5 6 struct dangdang 7 { 8 char email[30]; 9 char name[30]; 10 char addr[100]; 11 int num; 12 int bignum; 13 char tel[20]; 14 char phone[20]; 15 double rmb; 16 }; 17 18 main() 19 { 20 struct dangdang *p = (struct dangdang *)malloc(sizeof(struct dangdang) * 10); 21 int i; 22 struct dangdang *px; 23 24 for (i = 0;i < 10;i++)//下标循环 25 { 26 sprintf(p[i].email, "[email protected]"); 27 p[i].num = 100; 28 printf("%s,%d\n", p[i].email, p[i].num); 29 } 30 31 for (px = p;px < p + 10;px++)//指针循环px->email 32 { 33 sprintf(px->email, "[email protected]"); 34 px->num = 100; 35 printf("%s,%d\n", px->email, px->num); 36 } 37 38 for (i = 0;i < 10;i++)//指针循环(*(p + i)).email 39 { 40 sprintf((*(p + i)).email, "[email protected]"); 41 (*(p + i)).num = 100; 42 printf("%s,%d\n", (*(p + i)).email, (*(p + i)).num); 43 } 44 45 system("pause"); 46 };
时间: 2024-11-05 04:51:22