| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 906 人关注过本帖
标题:[求助]结构体变量作为函数参数
只看楼主 加入收藏
o0花生0o
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-10-13
收藏
 问题点数:0 回复次数:3 
[求助]结构体变量作为函数参数
#include<stdlib.h>
#include<stdio.h>
struct stud_type
{
char name[20];
long num;
int age;
char sex;
};
void main()
{
void list(struct stud_type student);
struct stud_type student[3],*p;
int i;
char numstr[20];
for(i=0,p=student;i<3;p++,i++)
{printf("Enter all data of student[%d]:\n",i);
scanf("%s%ld%d%c",p->name,&p->num,&p->age,&p->sex);
}
for(i=0;i<3;i++)
list(student[i]);
}
void list(student)
struct stud_type student;
{
printf("%-2s%8ld%6d%3c\n",student.name,student.num,student.age,student.sex);
}

这个程序在vc++编译时出现以下错误:C:\Documents and Settings\Administrator.F94E4AB1B271471\桌面\ckd.cpp(15) : warning C4101: 'numstr' : unreferenced local variable
C:\Documents and Settings\Administrator.F94E4AB1B271471\桌面\ckd.cpp(23) : error C2065: 'student' : undeclared identifier
C:\Documents and Settings\Administrator.F94E4AB1B271471\桌面\ckd.cpp(24) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
C:\Documents and Settings\Administrator.F94E4AB1B271471\桌面\ckd.cpp(24) : fatal error C1004: unexpected end of file found

该如何改正?
搜索更多相关主题的帖子: 变量 结构体 函数 参数 
2007-11-06 22:04
星空战士
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-10-25
收藏
得分:0 
好象是定义有问题

一切皆有可能,态度决定一切!
2007-11-06 22:11
学c
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-9-17
收藏
得分:0 

帮你改了一下:
#include<stdlib.h>
#include<stdio.h>
struct stud_type
{
char name[20];
long num;
int age;
char sex;
};
int main(void)
{
void list(struct stud_type student);
struct stud_type student[3],*p;
int i;
char numstr[20];
for(i=0,p=student;i<3;p++,i++)
{printf("Enter all data of student[%d]:\n",i+1);
scanf("%s %ld %d %c",p->name,&p->num,&p->age,&p->sex);
// getchar();
}
for(i=0;i<3;i++)
list(student[i]);
return 0;
}
void list(struct stud_type student)
// struct stud_type student;
{
printf("%-2s%8ld%6d%3c\n",student.name,student.num,student.age,student.sex);
}

2007-11-07 16:58
叶柄
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-10-17
收藏
得分:0 

#include<stdlib.h>
#include<stdio.h>
typedef struct stud_type
{
char name[20];//name
long num;//num
int age;//age
char sex;//sex
} Stud_type;
int main(void)
{
void list(Stud_type student);
Stud_type student[3],*p;
int i;

for(i=0,p=student;i<3;p++,i++)
{printf("Enter all data of student[%d]:\n",i+1);
scanf("%s %ld %d %c",p->name,&p->num,&p->age,&p->sex);
getchar();
}
for(i=0;i<3;i++)
list(student[i]);
return 0;
}
void list(Stud_type student)
// struct stud_type student;
{
printf("%-2s%8ld%6d%3c\n",student.name,student.num,student.age,student.sex);
}
char numstr[20];没用啊



2007-11-07 17:41
快速回复:[求助]结构体变量作为函数参数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016313 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved