: error : 'strcpy' : cannot convert parameter 1 from 'char' to 'char *' 帮忙看下啦
#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN5typedefstruct{inta[3];/...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 5
typedef struct
{
int a[3]; //各门课成绩
int total; //总分
double pj; //平均分
int dr; //排名
}learn;
typedef struct student
{
char num; //学号
char name; //姓名
char sex; //性别
int age; //年龄
learn degre; //成绩
struct student *next;
}Student;
Student *head=NULL;
void lianbiao() //从文件中读取学生信息放到链表中
{
FILE *fp;
if((fp = fopen("file1.txt","r")) == NULL)
{
printf("Could not open data file.\n");
exit(0);
}
head = (Student*)malloc(sizeof(Student));
Student *p = head;
for(int i = 0;i < N;i++)
{
Student stu;
fscanf(fp,"%d %s %s %d %d %d %f %d",&stu.num,&stu.name,&stu.sex,&stu.age,&stu.degre.a[0],&stu.degre.a[1],&stu.degre.a[2],&stu.degre.total,&stu.degre.pj,&stu.degre.dr);
Student *p = (Student*)malloc(sizeof(Student));
strcpy(p->num,stu.num); //这里有问题
strcpy(p->name,stu.name);
p->sex = stu.sex;
p->age = stu.age;
p->degre.a[0] = stu.degre.a[0];
p->degre.a[1] = stu.degre.a[1];
p->degre.a[2] = stu.degre.a[2];
p->degre.total = stu.degre.total;
p->degre.pj = stu.degre.pj;
p->degre.dr = stu.degre.dr;
if(i<N-1)
{
p->next = (Student*)malloc(sizeof(Student));
p = p->next;
}
p->next = NULL;
}
}
void show() //输出函数
{
Student *p = head;
printf("学号\t姓名\t性别\t年龄\t英语\t数学\t专业\t总分\t名次\n");
while(p != NULL)
{
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t\t%d\n",p->num,p->name,p->sex,p->age,p->degre.a[0],p->degre.a[1],p->degre.a[2],p->degre.total,p->degre.dr);
p = p->next;
}
}
void main()
{
lianbiao();
show();
} 展开
#include <string.h>
#include <stdlib.h>
#define N 5
typedef struct
{
int a[3]; //各门课成绩
int total; //总分
double pj; //平均分
int dr; //排名
}learn;
typedef struct student
{
char num; //学号
char name; //姓名
char sex; //性别
int age; //年龄
learn degre; //成绩
struct student *next;
}Student;
Student *head=NULL;
void lianbiao() //从文件中读取学生信息放到链表中
{
FILE *fp;
if((fp = fopen("file1.txt","r")) == NULL)
{
printf("Could not open data file.\n");
exit(0);
}
head = (Student*)malloc(sizeof(Student));
Student *p = head;
for(int i = 0;i < N;i++)
{
Student stu;
fscanf(fp,"%d %s %s %d %d %d %f %d",&stu.num,&stu.name,&stu.sex,&stu.age,&stu.degre.a[0],&stu.degre.a[1],&stu.degre.a[2],&stu.degre.total,&stu.degre.pj,&stu.degre.dr);
Student *p = (Student*)malloc(sizeof(Student));
strcpy(p->num,stu.num); //这里有问题
strcpy(p->name,stu.name);
p->sex = stu.sex;
p->age = stu.age;
p->degre.a[0] = stu.degre.a[0];
p->degre.a[1] = stu.degre.a[1];
p->degre.a[2] = stu.degre.a[2];
p->degre.total = stu.degre.total;
p->degre.pj = stu.degre.pj;
p->degre.dr = stu.degre.dr;
if(i<N-1)
{
p->next = (Student*)malloc(sizeof(Student));
p = p->next;
}
p->next = NULL;
}
}
void show() //输出函数
{
Student *p = head;
printf("学号\t姓名\t性别\t年龄\t英语\t数学\t专业\t总分\t名次\n");
while(p != NULL)
{
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t\t%d\n",p->num,p->name,p->sex,p->age,p->degre.a[0],p->degre.a[1],p->degre.a[2],p->degre.total,p->degre.dr);
p = p->next;
}
}
void main()
{
lianbiao();
show();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询