【发布时间】:2014-02-22 11:38:17
【问题描述】:
我收到另一个警告
C4047: 'initializing' : 'char *' 与 'int' 的间接级别不同。
为什么我会收到这些警告?我在 MSDN 上读到,如果我写了一个与我在头文件中写的不同的函数名,或者它应该是外部函数,它会生成。 有人能解释一下吗?
我的相关代码是:
GetSignature.c
#include "Parse_Database.h"
#include "Alloc_Mem.h"
#include "Get_Signature.h"
int Get_Signature(const char *filename) {
char *database = AllocMem(filename);
int error=0;
//ParseDatabase(database);
return 1;
}
AllocMem
#include "Alloc_Mem.h"
char *AllocMem(const char *filename) {
FILE *fp = NULL;
int ch = EOF;
char *buf = NULL, *tmp = NULL;
unsigned int size=0, index=0;
/*
Mallicous use of fopen(anyone could replace filename with a malicous modified file)
*/
fp = fopen(filename, "r");
if(fp == NULL) {
fprintf(stderr, "Can't open the signature database");
exit(1);
}
while(ch) {
fread(&ch, 1, 1, fp);
if(ch == EOF) {
ch = 0;
}
if(size <= index) {
size+=chunk;
tmp = realloc(buf, size);
if(!tmp) {
free(buf);
buf = NULL;
break;
}
buf = tmp;
}
buf[index++] = ch;
}
fclose(fp);
return buf;
}
Alloc_Mem.h
#ifndef HEADERFILE_H
#define HEADERFILE_H
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#define chunk 255
#include <stdio.h>
#include <stdlib.h>
char *AllocMem(const char *);
#endif
【问题讨论】:
-
另外,请确保您已为
exit()函数添加了#include <stdlib.h>。
标签: c