構造体について

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
DX

構造体について

#1

投稿記事 by DX » 18年前

//フォント構造体
typedef struct _BITMAPFONT
{
//フォントを書き出しのX座標
int offsetFontX;
//フォントを書き出しのY座標
int offsetFontY;
//フォントの横幅
int bitmapFontWidth;
//フォントの縦幅
int bitmapFontHeight;
} BITMAPFONT,*PBITMAPFONT;


void InitGame()
{
//フォントの自作構造体
BITMAPFONT bitmapFont;
PBITMAPFONT pBitmapFont = &bitmapFont;

createBitmapFont(&pBitmapFont);

}

呼び出し元がこうなっていて


void createBitmapFont(PBITMAPFONT *pBitmapFont)
{
//この部分で構造体のメンバにアクセスして代入したいのですが
  //コンパイルエラーがでてしまいます
*(pBitmapFont->offsetFontX) = 0;
}

PBITMAPFONT *pBitmapFontの引数の部分はポインタのポインタだから

*pBitmapFontで構造体のポインタになって

->をつかってアクセスできると思ったんですがなにがだめなのでしょうか??

Hermit

Re:構造体について

#2

投稿記事 by Hermit » 18年前

void
createBitmapFont (PBITMAPFONT * pBitmapFont)
{
  (*pBitmapFont)->offsetFontX = 0;
}
じゃないかな。

バグ

Re:構造体について

#3

投稿記事 by バグ » 18年前

代入するだけならば、ポインタでいいのではないでしょうか?
ポインタのポインタでなければいけない理由があるのならば、話は別ですが…?

閉鎖

“C言語何でも質問掲示板” へ戻る