用指针访问结构体数组(vc++ 结构体数组指针调用)

本文目录
vc++ 结构体数组指针调用
add H = new add;这句编译的时候应该通不过吧,一个是struct add一个是struct add *
add H = new add;
h-》a = i 改为H-》a = i;应该就可以了。
或者直接将:
add H = new add;改为add H;;
h-》a = i 改为H.a = i;
C语言关于指针访问结构体数据的使用
呵呵,很简单,你只要把x堪称一块内存就可以了。
x相当于:
+---------------------------+
|1|2|3|4|1|2|3|4|5|6|7|8|9|a|
+---------------------------+
|---n---|---------str-------|
我们从图中可以看到n其实占了四个字节的内存,而str占了10个字节。
那么str的地方,也可以 *(p + 9)形象的说明了跳过了9个字节。
C语言的指针结构体数组问题
#include 《stdio.h》
#include 《string.h》
struct stu{
int num;
char name;
char sex;
float score;
}boy={{101,"li ping",’m’,45},
{102,"zhang ping",’m’,62.5},
{103,"he fang",’m’,92.5},
{104,"cheng ling",’f’,87},
{106,"wang ming",’m’,58}};
struct node
{
struct stu num;
struct node *next;
};
main()
{
int i=0,bjg=0;
struct node s={0};
for (i=0;i《5;i++)
{
s.num;
strcpy(s.name);
s.sex;
s.score;
s;
}
s.next=NULL;
printf("不及格:\n");
for (i=0;i《5;i++)
{
if (s.num.score《60)
{
bjg++;
printf(".num.score);
}
}
printf("不及格人数【%d】\n",bjg);
}
不及格:
不及格人数【2】
Press any key to continue
不贴代码我就不调了 自己写了个
不说别的 光是malloc也不对啊 你不malloc struct node吗?
不malloc struct node 你的next指针存哪里?
至于链表赋值我就不看了
结构体数组指针
关键是输入的时候,不对了。
scanf("%s%d%c",&(stu.sex));
这句输入姓名是正确的,输入年龄也是正确的
输入年龄后的回车,会被sex接受到
下面我多声明一个变量ch专门接受回车的
另外,还修改了一下输出的格式
修改如下:
#include《stdio.h》
struct student
{
char name;
int age;
char sex;
};
void date_in(struct student stu,int n)
{
int i,ch;
for(i=0;i《n;i++)
{
printf("please input NO.%d stu:\n",i+1);
scanf("%s%d%c%c",&(stu.sex));
}
}
void date_pout(struct student *p,int n)
{
int i;
for(i=0;i《n;i++)
{
printf("NO.%d stu:\n",i+1);
puts(((p+i)-》name));
printf("%d\n",(p+i)-》age);
printf("%c\n",(p+i)-》sex);
}
}
void date_nout(struct student stu,int n)
{
int i;
for(i=0;i《n;i++)
{
printf("NO.%d stu:\n",i+1);
puts(stu.name);
printf("%d\n",stu.age);
printf("%c\n",stu.sex);
}
}
void main()
{
struct student stu;
int n=1;
date_in(stu,n);
date_pout(stu,n);
date_nout(stu,n);
}

更多文章:
html注册界面表单验证代码(html,js表单的验证,下面代码是想实现当输入6个字符以上用户名通过,少于时报错,但执行不了,求改错)
2025年6月23日 16:15
kali linux基础(变身滚动发行版,Kali Linux 2.0特性知多少)
2026年9月9日 23:45
access如何用查询值给一维数组赋值(如何用vb读取access表中数据,并赋值给另一变量然后进行计算判断 急!)
2025年9月7日 11:00
tp5666路由器(Tplink6500无线路由器怎么设置上网最流畅)
2025年11月18日 15:45
normal tanks第7关密码(请问normal tanks第五关以后的密码是多少诚挚谢谢!!)
2026年9月9日 02:00
编写webservice通讯接口(webservice接口怎么写)
2025年6月7日 15:45
尿常规中conduct是啥意思(尿常规报告单.请大家帮忙解读分析一下.)
2026年3月31日 19:30
简述php脚本程序工作流程(PHP脚本程序主要是由哪几部分组成)
2026年3月4日 15:15
java字符串截取后两位(JAVA截取所有指定字符后面的字符串)
2025年12月5日 23:15
告别php源码(apache 解析一个错误的php文件时,会直接显示php的源码,如何让他不显示源码)
2026年1月28日 18:00











