重点:指针自加,指向下一个结构体数组单元

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10
#define min 3 typedef struct Stu{
char * name;
int age;
int score;
} Stu; //输入
void input(Stu *);
void output(Stu *);
void clean(Stu *); void main(void)
{
Stu student[min];
input(student); //相当于传入&student[0] output(student);
clean(student);
} void input(Stu * student)
{
char temp[];
int i=;
puts("please input name");
while(i<min & gets(temp) != NULL & temp[] != '\0' )
{
student->name = (char *) malloc(strlen(temp)+);
strcpy(student->name,temp); puts("age ?");
scanf("%d",&student->age);
puts("score ?");
scanf("%d",&student->score); i++;
student++; //指针自加,指向下一个数组单元 while(getchar() != '\n')
continue; if(i<min)
puts("next name");
} } void output(Stu * student)
{
int i=;
while(i<min){
printf("%s---%d---%d\n",student->name,student->age,student->score);
i++;
student++;
} } void clean(Stu * student)
{
int i=;
while(i<min){
free(student->name);
i++;
student++;
}
}

c 用指针操作结构体数组的更多相关文章

  1. 嵌入式-C语言基础:通过结构体指针访问结构体数组

    #include<stdio.h> #include<string.h> struct Student { char name[32]; int age; int height ...

  2. 嵌入式-C语言:通过结构体指针操作结构体内容

    #include<stdio.h> #include<string.h> struct Student { char name[32]; int age; int height ...

  3. C#和C++互相操作 结构体数组的传递

    C++中结构体定义: typedef struct // 平面 { double time;  float normal[3]; float center[3];  } plane; C++中方法声明 ...

  4. C#调用C++DLL传递结构体数组的终极解决方案

    在项目开发时,要调用C++封装的DLL,普通的类型C#上一般都对应,只要用DllImport传入从DLL中引入函数就可以了.但是当传递的是结构体.结构体数组或者结构体指针的时候,就会发现C#上没有类型 ...

  5. 绝对好文C#调用C++DLL传递结构体数组的终极解决方案

    C#调用C++DLL传递结构体数组的终极解决方案 时间 2013-09-17 18:40:56 CSDN博客相似文章 (0) 原文  http://blog.csdn.net/xxdddail/art ...

  6. C语言 指向结构体数组的指针

    当结构体指针变量指向一个结构体变量数组的时候,此时指针变量的值就是结构体数组的首地址 关于如何定义结构体数组,和将结构体指针指向结构体变量数组,不是重点. 重点是,明白结构体指针的是怎么移动的, 我个 ...

  7. (60) 结构体指针、结构体变量嵌套、结构体指针嵌套、函数指针、数组指针、指针数组、typedef 综合运用

    #include<stdio.h> #include<iostream> #include<malloc.h> /* author : 吴永聪 program: 结 ...

  8. 【C++】结构体/结构体数组/结构体指针/结构体嵌套/函数参数/const

    一.结构体声明 struct Student { //成员列表 string name; int age; int score; }; //s3;定义时直接声明 int main() { struct ...

  9. Delphi结构体数组指针的问题

    //这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证 unit Unit1; interface uses Windows, Mess ...

随机推荐

  1. 笔记(assert 断言)

    并发:在同一个时间段交替执行多个任务并行:在同一个时间点同时执行多个任务串行:同时执行的多个任务按顺序执行(换句话说就是一个任务执行完后才能执行下一个任务) #mysql limit用法: selec ...

  2. Angular5学习笔记 路由配置

    因为angular-cli脚手架的关系,所以配置路由可以通过命令行来创建路由文件 原本创建一个angular项目的命令是ng new 项目名,就可以了,但这样创建出来的项目是没有路由文件的. 如果需要 ...

  3. html模板 练习(仿照抽屉网)

    1.页面布局 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  4. javaweb总结(四十)——编写自己的JDBC框架

    一.元数据介绍 元数据指的是"数据库"."表"."列"的定义信息. 1.1.DataBaseMetaData元数据 Connection.g ...

  5. 深入理解C++中的Const,Mutable以及Volatile

    我一直认为const表示一个常量,常量就是一个无法被修改的值,但是没有深入理解const的实现,甚至不知道mutable和volatile的存在,最近在书中看到了这一部分的知识,所以本文将详细解析这几 ...

  6. Firefox开发

    官方文档 First extension 目录结构 ➜ firefox tree . └── borderify └── manifest.json // 必须 directory, files ma ...

  7. VirtualBox虚拟机上安装windows7系统

    1.下载Windows7的镜像文件 http://www.xitongcheng.com/jiaocheng/win7_article_24156.html 2.在虚拟机上安装Windows7 htt ...

  8. IDEA 破解图文教程 - 2018.9 更

    你好!这里是你要找的 IDEA 破解方法 目录     一.前言    二.IDEA 安装         2.1 下载IDEA 旗舰版         2.2 开始安装         2.3 自定 ...

  9. JavaScript事件冒泡和捕获

    事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件. 事件冒泡是自下而上的去触发事件. 绑定事件方法的第三个参数,就是控制事件触发顺序是否为事件捕获.true,事件捕获:fa ...

  10. 软银集团和共享办公空间公司WeWork在日本成立合资公司

    [TechWeb报道]7月18日消息,据国外媒体报道,软银集团和共享办公空间公司WeWork联合宣布,在日本成立合资公司WeWork Japan. 该合资公司将在日本开设联合办公空间,于明年初在东京设 ...