• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
爱白菜的小昆虫
博客园    首页    新随笔    联系   管理    订阅  订阅

C/C++ 结构体 数组 函数传递

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 struct student{
 5     int num;
 6     char str[20];
 7     double dec;
 8 };
 9 
10 void scan(struct student stu[], int *n){
11     scanf("%d", n);
12     for(int i = 0; i < *n; ++i){
13         scanf("%d%s%lf", &stu[i].num, stu[i].str, &stu[i].dec);
14     }
15 }
16 
17 void print(struct student stu[], int n){    
18     printf("%d\n", n);
19     for(int i = 0; i < n; ++i){
20         printf("%d %s %lf\n", stu[i].num, stu[i].str, stu[i].dec);
21     }
22 }
23 
24 int main(){
25     int n;
26     struct student stu[10];
27 
28     scan(stu, &n);
29     print(stu, n);
30     
31     return 0;
32 }
33 /*
34 3
35 20 字符串0 20.02
36 21 字符串1 21.12
37 22 字符串2 22.22
38 */

 

posted @ 2016-12-11 13:58  爱白菜的小昆虫  阅读(5592)  评论(3)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3