Makefile与文件输入输出

主目录文件

其中有两个c文件和一个头文件,另外一个Make file和中间产生的test_print.txt文件其中file1.c为

/*************************************************************************
    > File Name: file1.c
    > Author: 
    > Mail: 
    > Created Time: Mon 01 Apr 2019 12:10:37 AM PDT
 ************************************************************************/
#include<iostream>
#include<stdio.h>
#include"file2.h"
#include<fstream>
#include<stdlib.h>

using namespace std;

int main(){
    FILE *fd = fopen("test_print.txt", "a+" );
    char s[] = "print file1 to file,and print file2 to screen";
    char  r[100] ;
    fprintf(fd,"%s", s);
    fread(r,sizeof(s)+1,1,fd);
    printf("%s\n", r);
    fclose(fd);
    file2Print();
    return 0;
}

 

file2文件为

/*************************************************************************
    > File Name: file2.c
    > Author: 
    > Mail: 
    > Created Time: Mon 01 Apr 2019 12:21:03 AM PDT
 ************************************************************************/

#include<stdio.h>
#include"file2.h"
void file2Print(){
    printf("printf file 2");
}

file2.h文件为

/*************************************************************************
    > File Name: file2.h
    > Author: 
    > Mail: 
    > Created Time: Mon 01 Apr 2019 12:14:04 AM PDT
 ************************************************************************/

#ifndef _FILE2_H
#define _FILE2_H

#ifdef __cplusplus
extern "C" {
#endif
 void file2Print();
#ifdef __cplusplus
}
#endif
#endi

Makefile文件为

print_name_file:file1.o file2.o
    g++ file1.o file2.o -o print_name_file
file1.o:file2.h
    g++ -c file1.c -o file1.o $(CXXPLAGS)
file2.o:file2.h
    g++ -c file2.c -o file2.o
clean:
    rm -rf *.o print_name_file test_print.txt

实现往test_print.txt文件里填写数据的基本功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值