pals. I found that the return value of fopen is different by the following two ways:
1.
int main()
{
FILE* fp_file = NULL;
fp_file = fopen(file_path, "wb");
if(NULL == fp_file)
return RET_NULL_POINT;
else
return RET_OK;
}
2.
int _open_file(const char* ps_file_path, const char* ps_open_mode, FILE* fp_arg)
{
if(NULL == ps_file_path || NULL == ps_open_mode)
{ return RET_INV_ARG;}
fp_arg = fopen(ps_file_path, ps_open_mode);
if(NULL == fp_arg)
{ return RET_NULL_POINT;}
else
{ return RET_OK;}// fp_arg is NULL after fopen, but it return RET_OK, why?
}
int main()
{
FILE* fp_file = NULL;
int i4_ret = 0;
i4_ret = _open_file((const char*)file_path, "wb", fp_file);
if(RET_OK != i4_ret)
{// do sth NG}
else
{// do sth OK}
......//NULL_POINT exception will be caused at some place below.
}
The file_path of 2) is same to 1). The result of 1) is return RET_OK, the result of i4_ret of 2) is RET_OK, but fp_file is NULL. I want to know why the fp_file of 1) is correct value, but in 2) it's NULL? There is no difference of arguments of fopen between 1) and 2).