新的结构 [英] new with structs

查看:152
本文介绍了新的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个处理结构的程序。

我需要帮助结构这是我第一次处理它们。你能给我一些有用的例子吗?

我的程序应该从两个输入文件中读取数据。

任何有关产品的信息都会有所帮助。


谢谢

解决方案

结构只是将相关信息存储在一起的有用方法。例如,让我们考虑以下非常简单的想法:


您是一名教师,并且您希望存储有关您学生的一些基本信息 - 他们的姓名,年龄和他们目前的成绩(满分100分)。你知道你可以这样编码:

展开 | 选择 | Wrap | 行号


只需添加一件事...如何使用指向结构的指针。

展开 | 选择 | Wrap | 行号


@donbock


确保为该结构分配一些内存,否则你会得到一大堆分段错误:

展开 | 选择 | Wrap | 行号

I am writing a program that deals with structs.
i need help with structs this is my first time dealing with them. can you give me some examples that would be helpful.
my program is supposed to have to read data from two input files.
any inforamtion on stucts will be helpful.

thank
you

解决方案

Structs are just a useful way to store related pieces of information together. For instance, let''s consider the following very simple idea:

You are a teacher, and you want to store some basic information about your students - their name, their age, and their current grade (out of 100). You know you can code it like this:

Expand|Select|Wrap|Line Numbers


Only one thing to add ... how to work with pointers to structures.

Expand|Select|Wrap|Line Numbers


@donbock
Make sure you allocate some memory for that struct, or you''ll get a whole bunch of segmentation faults:

Expand|Select|Wrap|Line Numbers


这篇关于新的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆