15 Ağustos 2017 Salı

fopen_s

Giriş
Açıklaması şöyle
fopen_s is a "secure" variant of fopen with a few extra options for the mode string and a different method for returning the stream pointer and the error code. It was invented by Microsoft and made its way into the C Standard.
Örnek
Okumak için şöyle yaparız.
#include <errno.h>
...
FILE *filepoint;
errno_t err;

if ((err = fopen_s(&filepoint, fileName, "r")) != 0) {
  // File could not be opened. filepoint was set to NULL
  // error code is returned in err.
  char buf[strerrorlen_s(err) + 1];
  strerror_s(buf, sizeof buf, err);
  fprintf_s(stderr, "cannot open file '%s': %s\n",
              fileName, buf);
} else {
    // File was opened, filepoint can be used to read the stream.
}

Hiç yorum yok:

Yorum Gönder