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

 #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. Docker学习笔记-Windows系统支持(一)

    Docker对windows的支持情况: 一.Docker for Windows ServerDocker Enterprise Edition for Windows Server 2016htt ...

  2. 基于Opencv的人脸检测及识别

    一.实验目的:我这里完成的是,将8张人脸图片(4组,每组两张)存入库中,选取1张图片,程序识别出与其匹配的另一张. 这里介绍分三个步骤完成该工作,①程序读取摄像头.拍照 ②程序从电脑文档中读取图片   ...

  3. Hadoop NameNode HA 和 ResourceManager HA

    1.集群规划 1.1 规划说明 hadoop1 cluster1 nameNode hadoop2 cluster1 nameNodeStandby ZooKeeper ResourceManager ...

  4. git clone、git pull和git fetch的用法及区别

    声明:码字不易,转载请注明出处,欢迎文章下方讨论交流.Git 常用命令速查表 最近在一个学习小组里学习AI的课程,我们所有的学习资料和homework都放在gitlab上.今天一个小队友从gitlab ...

  5. Javac提示不是内部或外部命令

    1.先去百度搜索"jdk下载"下载最新版jdk,并安装,安装目录不用去更改,直接默认就好,下载完了之后,双击打开安装,jdk安装完成后,会接着安装jre包,(jre和jdk是配对的 ...

  6. [转]git学习------>git-rev-parse命令初识

    git学习------>git-rev-parse命令初识 2017年06月13日 10:04:13 阅读数:2172 一.准备工作 第一步:在d盘git test目录下,新建工作区根目录dem ...

  7. qt linux系统下出现Qt5: Unknown module(s) in QT: serialport问题解决

    需要单独安装这个模块, manjaro linux打开包管理器,搜索安装,就好了

  8. 生成dataset的几种方式

    1.常用的方式通过sparksession读取外部文件或者数据生成dataset(这里就不讲了)  注: 生成Row对象的方法提一下:RowFactory.create(x,y,z),取Row中的数据 ...

  9. C# ArcFace 免费人脸识别 2.0 demo

    **配置过程:** 1. 到[虹软官网](https://ai.arcsoft.com.cn/index.htm?utm_source=csdn&utm_medium=referral)下载S ...

  10. Wacom将在CES 2015上发布全新旗舰版Cintiq

    Cintiq 27QHD和Cintiq 27QHD touch拥有宽大的工作表面,以及令人惊喜的屏幕笔触和颜色性能. 2015年1月6日,Wacom发布了Cintiq 27QHD和Cintiq 27Q ...