LoginSignup
3
0

More than 3 years have passed since last update.

Visual Studio 2019がうるさい

Posted at
#include <stdio.h>

int main(){

    FILE *fp1=NULL, *fp2=NULL;

    // ファイルを開く
    if (fopen_s(&fp1, "readfile.txt", "r") != 0) {
        printf("Read File not open\n");
        return -1;
    }
    // データの読み込み(省略

    // 書き込み用ファイルを開く
    if (fopen_s(&fp2, "writefile.txt", "w") != 0) {
        printf("Write File not open\n");
        return -1;
    }
    // 書き込み処理

    fclose(fp1);
    fclose(fp2);

    return 0;
}
警告  C6387   'fp1' は '0' である可能性があります: この動作は、関数 'fscanf_s' の指定に従っていません。
警告  C6387   'fp2' は '0' である可能性があります: この動作は、関数 'fprintf' の指定に従っていません。

こんなんでも文句言われるんだ。
とりあえず修正してワーニングエラー出ない様にした。

#include <stdio.h>

int main(){

    FILE *fp1=NULL, *fp2=NULL;

    // ファイルを開く
    if (fopen_s(&fp1, "readfile.txt", "r") != 0) {
        printf("Read File not open\n");
        return -1;
    }else{
        // データの読み込み(省略

        fclose(fp1);
    }

    // 書き込み用ファイルを開く
    if (fopen_s(&fp2, "writefile.txt", "w") != 0) {
        printf("Write File not open\n");
        return -1;
    }else{
        // データの書き込み(省略

        fclose(fp2);
    }
    return 0;
}

修正前の処理で0で通る可能性ってあるか?

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0