我有一个文件a.c
,a.h
它作为支持模块,具有其他文件中的功能。
在这些函数中,我必须打开一个文件并执行读取数据、写入数据、关闭它等功能。
出于这些目的,我给出了文件指针的全局a.c
声明
static FILE* pFile;
并pFile
直接使用。
编译器抛出错误的错误如下:
"pFile" not defined in the function
这里有什么问题?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <arpa/inet.h>
#define path "/tmp/diag.log"
FILE* pFile;
void a(bool value) {
if (value) {
pFile = fopen (path,"a");
return;
}
else if (!value) {
fclose (pFile);
}
}
void b(bool value) {
if(value)
{
fprintf (pFile,"%s",message);
}
}
更新:错误是我的 makefile 正在从构建目录中获取文件并且更改没有得到反映。非常感谢您的帮助