| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 394 人关注过本帖
标题:关于指针赋值的问题
只看楼主 加入收藏
小无相
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2012-7-24
结帖率:25%
收藏
已结贴  问题点数:10 回复次数:3 
关于指针赋值的问题
#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
等 级:论坛游民
帖 子:29
专家分:72
注 册:2012-3-21
收藏
得分:10 
struct stuent *p;  标红那个打错了~~
2012-08-02 18:51
小无相
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2012-7-24
收藏
得分:0 
这错误犯的......
2012-08-02 19:12
小糊涂神c30
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:3
帖 子:198
专家分:809
注 册:2012-4-25
收藏
得分:0 
scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
int _tmain(int argc, _TCHAR* argv[])
scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
p1=(struct student *)malloc(sizeof(struct student *));
红色部分没见过,不知道你用的是哪种编译器,最后一个申请内存的时候为什么老加上一个 * 呢,不明白,我用的vc6,把上面的改了,可以运行···楼主再看一下吧!
2012-08-02 19:18
快速回复:关于指针赋值的问题
数据加载中...
 
   



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

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