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 ...
随机推荐
- vue中-webkit-box-orient:vertical打包放到线上不显示
解决方法: 1.找到build文件夹 下的webpack.prod.conf.js文件 2.注释new OptimizeCSSPlugin({ css ...
- 20155217 实验四 Android程序设计
20155217 实验四 Android程序设计 任务一: 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号. R.java文件是定义该项目所有资源的 ...
- C语言 结构体学习
结构体的学习 struct 结构是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合. 结构中可以使用不同的数据类型. 结构说明和结构变量定义 在Turbo C中, 结构也是一种数据类型,可以 ...
- 20155334 2016-2017-2 《Java程序设计》第一周学习总结
20155334 2016-2017-2 <Java程序设计>第一周学习总结 教材学习内容总结 第一章主要讲了Java的前世今生以及Java的三大平台(Java SE.Java EE.Ja ...
- print puts p
共同点:都是用来屏幕输出的. 不同点:puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号):另外如果内容参数中有转义符,输出时将先处理转义再输出p 基本与puts相同,但不会处理 ...
- CF 833 B. The Bakery
B. The Bakery http://codeforces.com/contest/833/problem/B 题意: 将一个长度为n的序列分成k份,每份的cost为不同的数的个数,求最大cost ...
- 搭建 ssm 环境
<!-- 引入外部jdbc配置文件 --> <context:property-placeholder location="classpath:dbconfig.prope ...
- Python3中IO文件操作的常见用法
首先创建一个文件操作对象: f = open(file, mode, encoding) file指定文件的路径,可以是绝对路径,也可以是相对路径 文件的常见mode: mode = “r” # ...
- 用Micro:bit做剪刀、石头、布游戏
剪刀.石头.布游戏大家都玩过,今天我们用Micro:bit建一个剪刀.石头.布游戏! 第一步,起始 当你摇动它时,我们希望the micro:bit选择剪刀.石头.布.尝试创建一个on shake b ...
- KEIL5的安装
安装注意事项 1.最好不要安装在带有中文路径的文件夹. 2.试用版的Keil MDK只能编译32K以下的代码,代码大于32K只能使用正版或破解版才能编译通过. 安装MKD 这里选择MKD512A版本安 ...