0

私は構造について勉強していて、いくつかのエラーがあります。理由がわかりません。私を助けてください。

#include <stdio.h>

struct data{
    int x;
    float y;
    float z;
} info;

info.x = 100;

struct data *ptr;
ptr = &info;

(*ptr).y = 5.5;
(*ptr).z = 1.0;

int main(void)
{
    printf("The first member's value is %d.\n", info.x);
    printf("The second member's value is %.1f.\n", info.y);
    printf("The third member's value is %.1f.\n", info.z);

    return 0;
}

コンパイルエラーは

exercise112.c:10:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
 info.x = 100;
     ^
exercise112.c:13:1: warning: data definition has no type or storage class
 ptr = &info;
 ^~~
exercise112.c:13:1: warning: type defaults to ‘int’ in declaration of ‘ptr’ [-Wimplicit-int]
exercise112.c:13:1: error: conflicting types for ‘ptr’
exercise112.c:12:14: note: previous declaration of ‘ptr’ was here
 struct data *ptr;
              ^~~
exercise112.c:13:7: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
 ptr = &info;
       ^
exercise112.c:13:7: error: initializer element is not computable at load time
exercise112.c:15:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
 (*ptr).y = 5.5;
       ^
exercise112.c:16:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
 (*ptr).z = 1.0;
       ^
  1. 定義、宣言、初期化、または何か間違ったことをしましたか?
  2. エラーメッセージが何を言っているのかわかりません。彼らはどういう意味ですか?
4

0 に答える 0