I have defined functions in multiple files. I want to write some text to the same file according to their execution same as below. I have found the way to write execution flow in different in file as below.
function1.h
#ifndef FUNCTION1_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
int Sum(int a, int b);
#endif
function1.c
#include "function1.h"
int Sum(int a, int b)
{
FILE *fp;
fp = fopen("E:\\tmp\\test.txt", "a");
fputs("Inside Sum function...\n", fp);
fclose(fp);
return a+b;
}
main.c
#include "stdio.h"
#include "function1.h"
int main() {
int a=10, b=12;
FILE *fp;
fp = fopen("E:\\tmp\\test.txt", "a");
fputs("Before Sum function...\n", fp);
fclose(fp);
printf("%d + %d = %d", a, b, Sum(a, b));
fp = fopen("E:\\tmp\\test.txt", "a");
fputs("After Sum function...\n", fp);
fclose(fp);
}
Above solution is very difficult to handle when there are more multiple files. Is there direct way to write test.txt in multiple *.c files?