注册 登录
编程论坛 C++教室

帮忙看看那里出错了???

a382793896 发布于 2011-05-22 23:38, 486 次点击
程序代码:
# include <stdio.h>
# include <string.h>

struct student
{
   int age;
   char sex;
   char name;
};

void input(struct student *);
void output(struct student *);

int main(void)
{   
    struct student st;
    input(&st);
    output(&st);
   
    return 0;
}

void input(struct student *pst)
{
  (*pst).age = 10;

 错误在这--> strcpy(pst->name, "王二");
  pst->sex = '';

   return ;
}

void output(struct student *pstu)
{  
    printf ("%d%c%c",pstu->age,pstu->name,pstu->sex);

   return ;
}
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
6 回复
#2
hys19862011-05-22 23:46
char只是个单字吧
SEX 和 NAME都应该初始化成ARRAY而不是单字
#3
紫凤双飞2011-05-22 23:47
strcpy的两个参数都应该是字符串,而你的pst->name是char型的
应该把pst->name改为char*
#4
紫凤双飞2011-05-22 23:49
pst->sex = '男';这个应该也有问题吧
‘男’是两个字节啊
#5
lucky5635912011-05-23 07:56
name是数组而不是字符
#6
烟雾中的迷茫2011-05-24 06:22
楼上都正解啊 或者你把 char name  ,char sex 都改为数组啊
#7
a3827938962011-05-25 22:10
ok了!!
谢谢了!!
1