I find that the API,
_tfsopen()
is not working when I just give the relative file path (JUST FILE NAME) in
fopen_s(&fp,"FileName.txt",w+);
But if I give the absolute path of the txt file then it's working fine. So the problem is in getting the current working directory (CWD). How do I get the CWD and make this API work?
This API definition is present in:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\crt\src\fopen.c
This is what fopen.c has:
errno_t __cdecl _tfopen_s (
FILE ** pfile,
const _TSCHAR *file,
const _TSCHAR *mode
)
{
_VALIDATE_RETURN_ERRCODE((pfile != NULL), EINVAL);
*pfile = _tfsopen(file, mode, _SH_SECURE); // ERROR IS OCCURING AT THIS LINE. IT's NOT ABLE TO OPEN THE FILE.
if(*pfile != NULL)
return 0;
return errno;
}