使用宏C编程返回

che*_*123 0 c macros return

即使fopen()函数成功执行,此代码也始终返回-1.有什么我无视的东西.

void nullCheck(FILE* checkVar)  {
    if(checkVar==NULL)  {
        #define _NULL_ERROR
      }
    }

int readFile(char* _name, char* storeArray) {
FILE* fp;
fp=fopen(_name,READ_ONLY_MODE);
nullCheck(fp);
#ifndef _NULL_ERROR
    char c=0;
    while((c=getc(fp))!=EOF) {
        *(storeArray+i)=c;
        i+=1;
    }
#endif
#ifdef _NULL_ERROR
    #undef _NULL_ERROR
    return -1;
#endif
return 1;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Ern*_*ill 5

Oy va voy!编译代码时,宏定义和未定义,而不是在运行时!它们不受"if"和"then"之类的控制流语句的影响 - 它们都是在编译这些语句之前处理的!