前提・実現したいこと
構造体のメンバ変数?に格納した文字を比較したい
発生している問題・エラーメッセージ
構造体に格納した文字と比較したい文字が比較できない
該当のソースコード
C
#define _CRT_SECURE_NO_WARNINGS #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "conioex.h" #define MAX_MONSTERNAME (255) #define MAX_MONSTER (999) #define NOW_MONSTER (176) // 構造体 typedef struct { ~省略~ char Type[256]; ~省略~ }MONSTER; MONSTER Monster[MAX_MONSTER]; MONSTER* pMonster = &Monster[0]; //プロトタイプ宣言 void InputStatus(MONSTER*); void OutputStatus(MONSTER*, const char* a); int saidaisu; int main() { ~省略~ //ステータス入力 for (int i = 0; i < saidaisu; i++) { printf("%d体目を入力してください\n", i + 1); InputStatus(&pMonster[i]); } system("cls"); //ステータス表示 OutputStatus(&pMonster[saidaisu - 1], FILENAME); ~省略~ return 0; } void InputStatus(MONSTER* p) { printf("タイプ:"); scanf("%s", (&p->Type)); } void OutputStatus(MONSTER* p , const char* a) { for (int i = 0; i < saidaisu; saidaisu--) { if (pMonster[saidaisu - 1].Type == "赤") { fprintf(pFile, "%s", pMonster[saidaisu - 1].Type); } else if (pMonster[saidaisu - 1].Type == "青") { fprintf(pFile, "%s", pMonster[saidaisu - 1].Type); } else if (pMonster[saidaisu - 1].Type == "緑") { fprintf(pFile, "%s", pMonster[saidaisu - 1].Type); } else if (pMonster[saidaisu - 1].Type == "紫") { fprintf(pFile, "%s", pMonster[saidaisu - 1].Type); } else if (pMonster[saidaisu - 1].Type == "黄") { fprintf(pFile, "%s", pMonster[saidaisu - 1].Type); } else { fprintf(pFile, "なにこれ"); } }
試したこと
pMonster[saidaisu - 1].Typeを()で囲んでみる
赤、青、緑、紫、黄、のそれぞれを""ではなく''で囲んでみる
()で囲んでみるのは意味ありませんでした
''で囲むと==に赤線が引かれて、オペランド型に互換性がありません("char*"と"int")と出ます
補足情報(FW/ツールのバージョンなど)
VisualStudio2022
Windowsデスクトップウィザード
まだ回答がついていません
会員登録して回答してみよう