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 ...
随机推荐
- kubernetes基本概念和术语
一. kubernetes是什么 kubernetes是一个全新得基于容器技术得分布式架构领先方案.是google Borg得一个开源版本.Borg是google得一个久负盛名得内部使用得大规模集群管 ...
- 实验一 Java开发环境的熟悉(Linux+Eclipse)
实验一 Java开发环境的熟悉(Linux+Eclipse) 在Linux或Window或macOS中命令行下运行Java 在Linux 或Window或 macOS环境中 IDEA中调试设置断点 实 ...
- 《Java程序设计》课堂实践内容总结
<Java程序设计>课堂实践内容总结 实践一 要求 修改教材P98 Score2.java, 让执行结果数组填充是自己的学号: 提交在IDEA或命令行中运行结查截图,加上学号水印,没学号的 ...
- python 发红包的小程序
红包1 import random def redpacket(cash,person): lst=[] sum1=0 cash = cash * 100 while cash>0 and pe ...
- day2 RHCE
1.配置SELINUX 在system1和system2上要求SeLinux的状态为enforcing.要求系统重启后依然生效. server [root@server0 ~]# getenforce ...
- 单元测试或main方法 进行单元测试时 idea检查其他类的语法是否正确的去除方法
在进行单元测试或者main方法时,在 运行/调试 设置中设置想要使用的测试单位的 before launch 即可
- zookeeper 简单小节
1. ZooKeeper 是什么 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务.主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储 ...
- 获取安卓app的appPackage和appActivity
1.需要配置好android的开发环境后,打开cmd命令窗口 2.在命令窗口中输入,adb logcat>D:/log.log,抓取日志 3.运行启动app 4.查看日志log 5.搜索日志的关 ...
- mysql增删改查、连表查询、常用操作
一.建表 1.最简单的建表CREATE TABLE user(id int,name char(20),age int); 2.带主键带注释和默认值创建表CREATE TABLE user(id I ...
- python—退出ipython3的help()
退出ipython3的help() 组合键:ctrl+z