| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1523 人关注过本帖
标题:DEV-C++怎么链接文件
只看楼主 加入收藏
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 10楼 rjsp
...我重新建了工程,果然可以了。谢谢
另外头文件用宏防止重复包含是什么意思,能举个栗子吗
2015-09-10 22:02
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:15 
回复 11楼 w906414
随便打开个标准头文件看看就明白了
我手机上网,打字太难,你也可以自己google一下
2015-09-10 22:39
hjx1120
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:李掌柜
等 级:贵宾
威 望:41
帖 子:1314
专家分:6927
注 册:2008-1-3
收藏
得分:5 
#include <stdio.h>
#include <stdlib.h>
#include "names_st.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    names candidate;
    get_names(&candidate);
    printf("Let` s welcome ");
    show_names(&candidate);
    printf(" to this program!\n");
    return 0;
}

#define SLEN 32
struct names_st{
    char first[SLEN];
    char last[SLEN];
};
typedef struct names_st names;
void get_names(names *);
void show_names(const names *);

#include <stdio.h>
#include "names_st.h"

void get_names(names * pn){
    int i;
    printf("Please enter your first name :");
    fgets(pn->first,SLEN,stdin);
    i = 0;
    while(pn->first[i] != '\n' && pn->first[i] != '\0')
        i++;
    if (pn->first[i] == '\n')
        pn->first[i] = '\0';
    else
        while (getchar() != '\n')
            continue;
   
    printf("Please enter your last name: ");
    fgets(pn->last,SLEN,stdin);
    i = 0;
    while (pn->last[i] != '\n' && pn->last[i] != '\0')
        i++;
    if (pn->last[i] == '\n')
        pn->last[i] = '\0';
    else
        while (getchar() != '\n')
            continue;   
}

void show_names(const names * pn){
        printf("%s %s",pn->first,pn->last);
    }
useheader.zip (67.54 KB)

PS:附件的工程编译通过
2015-09-10 23:36
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
以下是引用w906414在2015-9-10 22:02:09的发言:

...我重新建了工程,果然可以了。谢谢
另外头文件用宏防止重复包含是什么意思,能举个栗子吗
比如某版本的 stdio.h 中,是若此做以防止重复包含
程序代码:
#ifndef _INC_STDIO
#define _INC_STDIO

…………

#endif  /* _INC_STDIO */

2015-09-11 08:15
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
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
回复 15楼 w906414
是这样
程序代码:
#ifndef NAMES_ST_H__ // 当然这个名字随便你取,只要不重复就行
#define 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*);

#endif  /* NAMES_ST_H__ */

2015-09-11 10:16
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.020983 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved