| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 1523 人关注过本帖
标题:DEV-C++怎么链接文件
取消只看楼主 加入收藏
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
结帖率:81.82%
收藏
已结贴  问题点数:20 回复次数:7 
DEV-C++怎么链接文件
有三个文件,第一个是头文件,声明了函数原型、定义了变量结构体等
            第二个是.c文件,定义了函数
            第三个是要运行的.c文件,调用函数,显示结果
编译显示链接错误,怎么才能把两个.c文件链接起来。。
2015-09-09 15:16
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 2楼 李掌柜
图片附件: 游客没有浏览图片的权限,请 登录注册

建了工程了,还是不得行啊

[ 本帖最后由 w906414 于 2015-9-9 15:35 编辑 ]
2015-09-09 15:34
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 4楼 hjx1120
程序代码:
//names_st.h
#define SLEN 32
struct names_st{
    char first[SLEN];
    char last[SLEN];
};
void get_names(struct names_st *);
void show_names(const struct names_st*);

//names_st.c
#include<stdio.h>
#include "names_st.h"
void get_names(struct names_st*p)
{
    int i;
    printf("Please enter your first name:");
    fgets(p->first,SLEN,stdin);
    i=0;
    while(p->first[i]!='\n'&&p->first[i]!='\0')
        i++;
    if(p->first[i]=='\n')
        p->first[i]='\0';
    else
        while(getchar()!='\n')
            continue;
    printf("Please enter your last name:");
    fgets(p->last,SLEN,stdin);
    i=0;
    while(p->last[i]!='\n'&&p->last[i]!='\0')
        i++;
    if(p->last[i]=='\n')
        p->last[i]='\0';
    else
        while(getchar()!='\n')
            continue;
}
void show_names(const struct names_st*p)
{
    printf("%s %s\n",p->first,p->last);
}

书上的代码
2015-09-09 16:46
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 6楼 hjx1120
。。。主程序在图片里就没贴
程序代码:
#include<stdio.h>
#include "names_st.h"
int main(void)
{
    struct names_st cand;
    get_names(&cand);
    printf("Let us welcome");
    show_names(&cand);
    puts("to this program!");
}
2015-09-09 19:52
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 7楼 rjsp
是c,之前没发现一个是cpp,后来改过来了 还是不行
2015-09-09 19:53
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 10楼 rjsp
...我重新建了工程,果然可以了。谢谢
另外头文件用宏防止重复包含是什么意思,能举个栗子吗
2015-09-10 22:02
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 14楼 rjsp
程序代码:
#ifndef SLEN 
#define SLEN 32
#endif
struct names_st{
    char first[SLEN];
    char last[SLEN];
};
void get_names(struct names_st *);
void show_names(const struct names_st*);

是这样吗,后面的函数和结构体声明是不是因为只是声明,不用处理啊。
2015-09-11 09:13
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 16楼 rjsp
明白了
2015-09-11 12:48
快速回复:DEV-C++怎么链接文件
数据加载中...
 
   



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

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