主目录文件
其中有两个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文件里填写数据的基本功能