プロが教えるわが家の防犯対策術!

\source.cpp(37): error C2440: '=' : 'errno_t' から 'FILE *' に変換できません。
1> 整数型からポインター型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
\source.cpp(58): error C2440: '=' : 'errno_t' から 'FILE *' に変換できません。
1> 整数型からポインター型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
とエラーが出たのですがどのように直したらいいでしょうか?

#include <stdio.h>
#include <process.h>



#define X_SIZE 200 // 処理できる最大画像
#define Y_SIZE 160

#define LX_SIZE 400 // 処理できる最大画像
#define LY_SIZE 320

#define HIGH 255 // 画像の最大強度値
#define LOW 0 // 画像の最小強度値
#define LEVEL 256 // 画像の強度レベル値

// BMPファイルのフォーマットに従って用意した変数
typedef unsigned short WORD;
typedef unsigned long DWORD;


unsigned char image_in[Y_SIZE][X_SIZE][3]; // 入力カラー画像配列
unsigned char image_out[LY_SIZE][LX_SIZE][3]; //出力カラー画像配列



//********************************************
// 24Bit RAW ファイル読み込み *
//********************************************
void readRAW(
char *filename, // RAW画像ファイル名
unsigned char image[Y_SIZE][X_SIZE][3] // 24ビットRGB画像配列
)
{
FILE *fp;

// ファイルオープン
if ((fp = fopen_s(&fp, filename, "rb")) == NULL) {
printf("readRAW: Open error!\n");
exit(1);
}
printf("input file : %s\n", filename);

fread(image, 1, X_SIZE*Y_SIZE * 3, fp);
fclose(fp);
}


//******************************************************
// 24ビット-ビットマップデータをRAWファイルに出力 *
//******************************************************
void writeRAW(
char *filename,
unsigned char image[LY_SIZE][LX_SIZE][3])
{
FILE *fp;

// ファイルオープン
if ((fp = fopen_s(&fp,filename, "wb")) == NULL) {
printf("writeRAW: Open error!\n");
exit(1);
}
printf("output file : %s\n", filename);

fwrite(image, 1, LX_SIZE*LY_SIZE * 3, fp);
fclose(fp);

}


//**********************************************
// RGBカラー画像を二倍拡大         *
//**********************************************
void Image_2bai(
unsigned char image_in[Y_SIZE][X_SIZE][3],
unsigned char image_out[LY_SIZE][LX_SIZE][3])
{
int y, x, z;

for (y = 0; y<Y_SIZE; y++)
for (x = 0; x< X_SIZE; x++)
for (z = 0; z<3; z++){
image_out[2 * y][2 * x][z] = image_in[y][x][z];
image_out[2 * y][2 * x + 1][z] = image_in[y][x][z];
image_out[2 * y + 1][2 * x][z] = image_in[y][x][z];
image_out[2 * y + 1][2 * x + 1][z] = image_in[y][x][z];
}
for (y = 0; y<Y_SIZE / 2; y++)
for (x = 0; x< X_SIZE / 2; x++)
for (z = 0; z<3; z++){
image_out[y][x][z] = image_in[2 * y][2 * x][z];
}
}



void main(void)
{
char input_name[100], output_name[100];

printf("入力画像ファイル名(*.raw):"); scanf("%s", input_name);

readRAW(input_name, image_in); // 画像の入力,RGB24ビットカラーBMP画像を配列に格納


//画像処理:左右反転
Image_2bai(image_in, image_out); // RGBカラー画像を白黒画像に変換
printf("左右反転画像ファイル名(output_name.raw):"); scanf("%s", output_name);
writeRAW(output_name, image_out); // 画像出力

}

A 回答 (2件)

fopen_s()ではなくfopen()を使う。

というのも有りです。
というか、既にそういう回答もらっていますよね。
SYさん?それともHIRO31さん?はたまたgyukiさん?
    • good
    • 0

>\source.cpp(37): error C2440: '=' : 'errno_t' から 'FILE *' に変換できません。


>1> 整数型からポインター型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
>\source.cpp(58): error C2440: '=' : 'errno_t' から 'FILE *' に変換できません。
>1> 整数型からポインター型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
>とエラーが出たのですがどのように直したらいいでしょうか?

リファレンスくらい見ましょう。
VisualStudioなら関数にカーソル合わせてF1キー押せば表示されませんか?
https://msdn.microsoft.com/ja-jp/library/z5hh6ee …

ファイルポインタは第1引数に格納されて返されますので、戻り値が0だったら正常終了です。

if ((fp = fopen_s(&fp, filename, "rb")) == NULL) {

if (fopen_s(&fp, filename, "rb") != 0) {
でよいでしょう。
# エラー表示するならerrno_t型の変数に一度受け取って、その後のprintf()で出力すればよいかと。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!