标题:关于指针赋值的问题
取消只看楼主
小无相
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2012-7-24
结帖率:25%
已结贴  问题点数:10 回复次数:1 
关于指针赋值的问题
#include "stdafx.h"
#include "stdlib.h"
int n=0;
struct student
{
    int num;
    float scores;
    struct student *next;

};
struct student * construct()//创建链表
{   
    struct student *head,*p1,*p2;
    p1=(struct student *)malloc(sizeof(struct student *));
    p2=p1;
    head=p1;
    scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
    while(1)
    {
        p1=(struct student *)malloc(sizeof(struct student *));
        scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
        if(p1->num ==0)
        {
            p2->next=NULL;
            break;
        }
        else
        {
            p2->next =p1;
            p2=p1;
            n=n+1;
        }
     
    }
    return head;
}
void print(struct student * stu)//输出链表
{    struct student * st;
     st=stu;
     do
     {
         printf("%d %f\n",st->num ,st->scores );
         st=st->next ;
     }while(st!=NULL);
}
int _tmain(int argc, _TCHAR* argv[])
{
        struct stuent *p;
        p=construct();//这里不能赋值错误    1    error C2440: “=”: 无法从“student *”转换为“wmain::stuent *”
        print(p);//这里的参数也不对
        return 0;
}
搜索更多相关主题的帖子: next include scores 
2012-08-02 18:46
小无相
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2012-7-24
得分:0 
这错误犯的......
2012-08-02 19:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-374615-1-1.html




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

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