   fopen_s stopped working on me!
  Hi all.I've been working with visual studio and c++ for a few years now but I can't seem to get past this one! Im simply using fopen / fopen_s to open a config file. Wierdest thing is, this runs fine when building a release but crashes when building a debug. My properties for each build are almost identical except for optimizations.This code was written weeks ago and has not changed but as of yesterday fopen_s will not open my file properly. Im not sure what is going on.errno_t pErr=0;FILE* initFile=0;if( (pErr= fopen_s( &initFile, pInitfileName, "r" )) !=0 ){    Log()->Write( ERR_LEVEL::FATAL, "[Error] Cannot open %f", pInitfile);    return E_FAIL;}char filestring[256];fscanf_s( initFile, "%s", filestring )When stepping through, fopen_s returns 0 and actually writes to initFile (so it finds the file ) but looking it the pointer it seems to be a <Bad Ptr>Im using vista by the way in case that counts :)Has anyone run into anything like this before??   
  The code you posted shouldn't write to initFile since you're opening it for reading.Is it working in release mode or just not crashing?If it's operating correctly in release mode, I'd guess that you don't have your working directory set for debugging (Project | Properties | Debugging | Working Directory) and your program isn't finding the file when you step through.;Quote:Original post by ElectricSethHi all.I've been working with visual studio and c++ for a few years now but I can't seem to get past this one! Im simply using fopen / fopen_sI don't know if you heard the news, but there's this fancy new set of classes called 'iostreams' that were added to the C++ standard library, oh, almost eleven years ago. You might want to check them out. There's also this clever wrapper for strings, called 'string', that makes them behave like real data types instead of weird pointer/buffer hacks - by actually making them real data types instead of weird pointer/buffer hacks.std::string InitfileName; // replaces pInitfileName// Assuming that got set somewhere...std::istream initFile(InitfileName.c_str());if (!initFile) {  // A new-style logging system would probably make use of syntax more like this:  Log(ERR_LEVEL::FATAL) << "[Error] Cannot open " << InitfileName;  // I have no idea what you were expecting 'pInitfile' to be (no such  // identifier in your code), or why you were trying to format it as a float.  return E_FAIL;}std::string filestring;std::getline(initFile, filestring);By the way, your choice of IDE oughtn't affect the code that you write.   