c 用指针操作结构体数组
重点:指针自加,指向下一个结构体数组单元
#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 用指针操作结构体数组的更多相关文章
- 嵌入式-C语言基础:通过结构体指针访问结构体数组
#include<stdio.h> #include<string.h> struct Student { char name[32]; int age; int height ...
- 嵌入式-C语言:通过结构体指针操作结构体内容
#include<stdio.h> #include<string.h> struct Student { char name[32]; int age; int height ...
- C#和C++互相操作 结构体数组的传递
C++中结构体定义: typedef struct // 平面 { double time; float normal[3]; float center[3]; } plane; C++中方法声明 ...
- C#调用C++DLL传递结构体数组的终极解决方案
在项目开发时,要调用C++封装的DLL,普通的类型C#上一般都对应,只要用DllImport传入从DLL中引入函数就可以了.但是当传递的是结构体.结构体数组或者结构体指针的时候,就会发现C#上没有类型 ...
- 绝对好文C#调用C++DLL传递结构体数组的终极解决方案
C#调用C++DLL传递结构体数组的终极解决方案 时间 2013-09-17 18:40:56 CSDN博客相似文章 (0) 原文 http://blog.csdn.net/xxdddail/art ...
- C语言 指向结构体数组的指针
当结构体指针变量指向一个结构体变量数组的时候,此时指针变量的值就是结构体数组的首地址 关于如何定义结构体数组,和将结构体指针指向结构体变量数组,不是重点. 重点是,明白结构体指针的是怎么移动的, 我个 ...
- (60) 结构体指针、结构体变量嵌套、结构体指针嵌套、函数指针、数组指针、指针数组、typedef 综合运用
#include<stdio.h> #include<iostream> #include<malloc.h> /* author : 吴永聪 program: 结 ...
- 【C++】结构体/结构体数组/结构体指针/结构体嵌套/函数参数/const
一.结构体声明 struct Student { //成员列表 string name; int age; int score; }; //s3;定义时直接声明 int main() { struct ...
- Delphi结构体数组指针的问题
//这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证 unit Unit1; interface uses Windows, Mess ...
随机推荐
- Django模型中的元选项和object对象
1.元选项,在模型类型中定义一个Meta类,用于设置元信息 class Student(models.Model): name = models.CharField(max_length=20) se ...
- Java程序设计 第16周 课堂实践 —— 数据库4
Java程序设计 第16周 课堂实践 -- 数据库4 课堂实践任务4 查询world数据库,查询哪个国家的平均寿命最长. 代码分析 实现查询数据库需要我们修改Message.java,MessageD ...
- 20155318 《Java程序设计》实验二 (Java面向对象程序设计)实验报告
20155318 <Java程序设计>实验二 (Java面向对象程序设计)实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉 ...
- 20155325 信息安全技术 实验二 Windows口令破解
内容一览 实验结果 遇到的问题 思考题 详细步骤与解析(为了使存做笔记资料而做) 实验结果 字典破解 暴力破解 -不同密码强度的破解时间比较 用户名 密码 破解方式 破解时间 TEST (年月日) 字 ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛
A There is a tree with nn nodes, at which attach a binary 64*6464∗64 matrix M_i (1 \le i \le n)M i ...
- PostgreSQL的checkpoint能否并行
对于此问题,在社区进行了提问,并得到了一些大牛的解答: http://postgresql.1045698.n5.nabble.com/Can-checkpoint-creation-be-paral ...
- [BZOJ2961]共点圆-[凸包+cdq分治]
Description 传送门 Solution 考虑对于每一个点: 设圆的坐标为(x,y),点的坐标为(x0,y0).依题意得,当一个点在圆里,需要满足(x-x0)2+(y-y0)2<=x2+ ...
- python 逆波兰式
逆波兰式,也叫后缀表达式 技巧:为简化代码,引入一个不存在的运算符#,优先级最低.置于堆栈底部 class Stack(object): '''堆栈''' def __init__(self): se ...
- 【BZOJ3144】[HNOI2013]切糕
[BZOJ3144][HNOI2013]切糕 题面 题目描述 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑 ...
- springmvc controller常见问题
controller 的各种操作都是依赖服务器启动后来注入很多功能的,所以热部署经常会没有效果(因为没有被注入,除非在 方法名() 的括号中定义对象 [ 例如: HttpServletResponse ...