一道c语言数组指针的题目 帮忙看看哪里出错了
#include<stdio.h>#include<string.h>main(){structstudent{intno;/*学号*/charname[8];/*姓名*...
#include <stdio.h>
#include <string.h>
main(){
struct student
{ int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
/*用结构体类型来定义*/
#include <stdio.h>
#include <string.h>
struct student
{ int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
main()
{
char str[10];
int i;
do
{ printf("Enter a name:");
scanf("%s",str);
for (i=0;i<3;i++)
if( strcmp(str,stu[i].name)==0 )
{ printf("No :%d\n",stu[i].no);
printf("Name :%8s\n", stu[i].name );
printf("Score :%d\n",stu[i].score);
break;
}
if (i>=3) printf("Not Found\n");
}while (strcmp(str,"0")!=0);
}
----------------------------------
题目如上,
运行的时候出现几个错误,
小弟刚学c语,
不知道怎么改,
帮帮忙,,
谢谢了。。
说对了加分。 展开
#include <string.h>
main(){
struct student
{ int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
/*用结构体类型来定义*/
#include <stdio.h>
#include <string.h>
struct student
{ int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
main()
{
char str[10];
int i;
do
{ printf("Enter a name:");
scanf("%s",str);
for (i=0;i<3;i++)
if( strcmp(str,stu[i].name)==0 )
{ printf("No :%d\n",stu[i].no);
printf("Name :%8s\n", stu[i].name );
printf("Score :%d\n",stu[i].score);
break;
}
if (i>=3) printf("Not Found\n");
}while (strcmp(str,"0")!=0);
}
----------------------------------
题目如上,
运行的时候出现几个错误,
小弟刚学c语,
不知道怎么改,
帮帮忙,,
谢谢了。。
说对了加分。 展开
展开全部
#include <stdio.h>
#include <string.h>
struct student
{
int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
/*用结构体类型来定义*/
main()
{
char str[10];
int i;
do
{
printf("Enter a name:");
scanf("%s",str);
for (i=0;i<3;i++)
if( strcmp(str,stu[i].name)==0 )
{
printf("No :%d\n",stu[i].no);
printf("Name :%8s\n", stu[i].name );
printf("Score :%d\n",stu[i].score);
break;
}
if (i>=3)
printf("Not Found\n");
}while (strcmp(str,"0")!=0);
}
其实你写的还不错嘛~~~~~虽然我还没看呢~~~
运行下没错误啦~~
#include <string.h>
struct student
{
int no; /*学号*/
char name[8]; /*姓名*/
int score; /*学习成绩*/
};
struct student stu[]={{10,"Tom",90},{11,"Jerry",80},{12,"Harold",70}};
/*用结构体类型来定义*/
main()
{
char str[10];
int i;
do
{
printf("Enter a name:");
scanf("%s",str);
for (i=0;i<3;i++)
if( strcmp(str,stu[i].name)==0 )
{
printf("No :%d\n",stu[i].no);
printf("Name :%8s\n", stu[i].name );
printf("Score :%d\n",stu[i].score);
break;
}
if (i>=3)
printf("Not Found\n");
}while (strcmp(str,"0")!=0);
}
其实你写的还不错嘛~~~~~虽然我还没看呢~~~
运行下没错误啦~~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询