fopen_s

VS2005中的fopen和fopen_s學習
    

                            Warning and Warning coding

warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. 

To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wchar.h>

VOID main(int argc, char *argv[])
{
 FILE *fpStream, *fpDate;
 if (argc != 3)
 {
  return;
 }
  if((fpStream = fopen(argv[1], "rb")) == NULL)
  {
  printf("The file cannot be open!/n");
  }
  if((fpDate = fopen(argv[2], "wb")) == NULL)
  {
  printf("cannot open file!/n");  
 }
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#define _CRT_SECURE_NO_DEPRECATE      // Add by Nigel Yan 2008-10-21
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wchar.h>

VOID main(int argc, char *argv[])
{
 FILE *fpStream, *fpDate;
 if (argc != 3)
 {
  return;
 }
  if((fpStream = fopen(argv[1], "rb")) == NULL)
  {
  printf("The file cannot be open!/n");
  }
  if((fpDate = fopen(argv[2], "wb")) == NULL)
  {
  printf("cannot open file!/n");  
 }
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wchar.h>
VOID main(int argc, char *argv[])
{
 FILE *fpStream, *fpDate;
 errno_t err;          //定義一個這樣的變量 Add by Nigel Yan 2008-10-21
 if (argc != 3)
 {
  return;
 }
//用fopen_s函數用法。用法如下:test.xml test1.xml是要讀寫的文件名字,和要寫的文件的名字。
//不是((fpStream = fopen(argv[1], "rb")) == NULL)而是下面這兩個寫法。Add by Nigel Yan 2008-10-21
 if((err = fopen_s(&fpStream,"test.xml", "rb")) != 0)
 {
  printf("The file cannot be open!/n");
 }
 if((err = fopen_s(&fpDate,"test1.xml", "wb")) != 0)
 {
  printf("cannot open file!/n");
 }
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
Warring: At last the function of strcpy may be have this warning in VS

 

你可能感兴趣的:(c,function,File,null)