当前位置: 代码迷 >> C语言 >> 结构体问题
  详细解决方案

结构体问题

热度:352   发布时间:2006-10-11 18:12:14.0
结构体问题

#include<string.h>
#include<stdio.h>
void main()
{
struct student
{
long num;
char name[20];
char sex;
float score;
}
struct student stu_1;
struct student *p;

p=&stu_1;
stu_1.num=89101;
strcpy (stu_1.name, "Li Li");
stu_1.sex='M';
stu_1.score=89.5;
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
stu_1.num, stu_1.name, stu_1.sex, stu_1.score);
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
(*p).num, (*p).name, (*p).sex, (*p).score);

}
大家帮我看看这个问题哦!

搜索更多相关的解决方案: stu  结构体  struct  score  name  

----------------解决方案--------------------------------------------------------
以下是引用☆暂⊙帜☆在2006-10-11 18:12:14的发言:

#include<string.h>
#include<stdio.h>
void main()
{
struct student
{
long num;
char name[20];
char sex;
float score;
}
struct student stu_1;
struct student *p;

p=&stu_1;
stu_1.num=89101;
strcpy (stu_1.name, "Li Li");
stu_1.sex='M';
stu_1.score=89.5;
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
stu_1.num, stu_1.name, stu_1.sex, stu_1.score);
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
(*p).num, (*p).name, (*p).sex, (*p).score);

}
大家帮我看看这个问题哦!

红色的去掉就可以拉...解决拉...
呵呵...


----------------解决方案--------------------------------------------------------

以下是引用☆暂⊙帜☆在2006-10-11 18:12:14的发言:

#include<string.h>
#include<stdio.h>
struct student
{
long num;
char name[20];
char sex;
float score;
};

void main()
{
struct student stu_1;
struct student *p;

p=&stu_1;
stu_1.num=89101;
strcpy (stu_1.name, "Li Li");
stu_1.sex='M';
stu_1.score=89.5;
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
stu_1.num, stu_1.name, stu_1.sex, stu_1.score);
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
(*p).num, (*p).name, (*p).sex, (*p).score);

}
大家帮我看看这个问题哦!


----------------解决方案--------------------------------------------------------
2楼的肯定不对!
虽然我不是强者!
----------------解决方案--------------------------------------------------------

以下是引用baisea2001在2006-10-13 17:22:42的发言:
2楼的肯定不对!
虽然我不是强者!

呵呵..二楼去掉红色代码是正确的

其实就是少了个分号.要不怎么写都正确.

结构体后面要加分号.


----------------解决方案--------------------------------------------------------
以下是引用baisea2001在2006-10-13 17:22:42的发言:
2楼的肯定不对!
虽然我不是强者!


呵呵``` 你门在机器上面可以看看 对不对哦...
肯定是正确的...只是把两中方法混用拉~~~


----------------解决方案--------------------------------------------------------
以下是引用☆暂⊙帜☆在2006-10-11 18:12:14的发言:

#include<string.h>
#include<stdio.h>
void main()
{
struct student
{
long num;
char name[20];
char sex;
float score;
}stu_1; //相当于结构体student定义一个变量是stu_1;所以这个程序是正确的.
struct student *p;

p=&stu_1;
stu_1.num=89101;
strcpy (stu_1.name, "Li Li");
stu_1.sex='M';
stu_1.score=89.5;
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
stu_1.num, stu_1.name, stu_1.sex, stu_1.score);
printf (" NO.:%ld\n name:%s\n sex:%c\n score:%f\n",
(*p).num, (*p).name, (*p).sex, (*p).score);

}
大家帮我看看这个问题哦!


----------------解决方案--------------------------------------------------------

  相关解决方案