| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 458 人关注过本帖
标题:指针函数的调用与返回
只看楼主 加入收藏
chichu
Rank: 2
来 自:安徽阜阳
等 级:论坛游民
帖 子:71
专家分:89
注 册:2010-4-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
指针函数的调用与返回
程序报错为:cannot convert parameter 1 from 'struct stu' to 'struct stu *'
我定义的sa、Hc、hc都为同一类型的啊
不知道错在哪
知道的请指点下
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#define NULL 0                                
#define SIZ sizeof(struct stu)                 
struct stu                                    
{
    int num;
    stu *next;
};
stu *r,*s;                                                     
void main()
{
    stu * same(stu *ha,stu *hb);
    stu *Ha = NULL; stu *Hb = NULL; stu *Hc = NULL; //定义头指针
    int x;
    cout << "in put A:" << endl;                      //建立单链表A
    cin >> x;
    r = Ha;
    for(; x ;cin >> x)                              
    {                       
        s = (stu*) malloc(SIZ);
        s->num = x;
        if(Ha == NULL)
            Ha = s;
        else
            r->next = s;
        r = s;
    }                           
    if(r != NULL)
        r->next = NULL;
    r = Ha;                                   
    while(r != NULL)
    {
        cout << r->num <<" ";
        r = r->next;
    }
     cout << endl;
    cout << "in put B:" << endl;                      //建立单链表B
    cin >> x;
    r = Hb;
    for(; x ; cin>>x)
    {
        s = (stu*)malloc(SIZ);
        s->num = x;
        if(Hb == NULL)                     
            Hb = s;
        else
            r->next = s;
        r = s;
    }
    if(r != NULL)
        r->next = NULL;
    r = Hb;
    while(r != NULL)                           
    {
        cout << r->num <<" ";
        r = r->next;
    }
     cout << endl;
     Hc = same( *Ha, *Hb);
     r = Hc;
     while(r != NULL)
     {
         cout << r->num <<" ";
         r = r->next ;
     }
     free(s);
}
stu *same(stu *ha,stu *hb)
{
    stu *hc = NULL;
    r = hc;
    stu *q = ha;
    stu *p = hb;
    s = (stu*)malloc(SIZ);
    while(p != NULL && q != NULL)            //值相同时,插入c中
    {
        if(p->num = q->num)
        {
            s->num = p->num ;
            if(hc == NULL)
            {
                hc = s;
            }
            else
            {
                r->next = s;
                r = s;
            }
            s = (stu*)malloc(SIZ);
            p = p->next ;
            q = q->next ;
        }
        else
        {
            if(p->num < q->num )
            {
                p = p->next ;
            }
            else
            {
                q = q->next ;
            }
        }
               
    }
    if(r != NULL)
        r->next = NULL;
    return hc;
}
搜索更多相关主题的帖子: 指针 函数 
2010-04-22 10:51
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:20 
其他有没有错误没看
根据提示马上就知道你调用函数时实参传错了
Hc = same( *Ha, *Hb);应该改成Hc = same(Ha, Hb);
出现这错误说明你对指针的掌握还不是很熟
再复习一遍吧。。。

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2010-04-22 10:55
chichu
Rank: 2
来 自:安徽阜阳
等 级:论坛游民
帖 子:71
专家分:89
注 册:2010-4-14
收藏
得分:0 
谢谢

有了目标才有动力!!!
2010-04-22 10:58
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
不客气
把基础一定要夯实啊。。。

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2010-04-22 11:00
快速回复:指针函数的调用与返回
数据加载中...
 
   



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

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