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

#1

投稿記事 by ニロ » 13年前

C言語の初心者です。
以下のような、ファイルを読み込んでSCORE型変数に読み込むプログラムを作っているのですが、矢印で示したようなエラーが出ます。自分では解決できなかったのでどこを直せばいいのか教えて頂けないでしょうか。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{

int mat;
int eng;
int phy;
}SUBJECT;

typedef struct{
int no;
char name[20];

SUBJECT sub;
double ave;
int sum;
}SCORE;

SCORE InputStudentData2(
int st.no,  //←expected ‘;’, ‘,’ or ‘)’ before ‘.’ token
char st.name[],
int st.sub.mat,
int st.sub.eng,
int st.sub.phy)
{
SCORE tmp;

tmp.no=no;
stcopy(tmp.name,name);
tmp.sub.mat=mat;
tmp.sub.eng=eng;
tmp.sub.phy=phy;

return tmp;
}

int main (void)
{
int i,dm;
FILE *fp[2];

fp[0]=fopen("st_name.dat","r");
fp[1]=fopen("st_sub.dat","r");

SCORE st[8];

for(i=0;i<9;i++){
fscanf(fp[0],"%d %s",&st.no,st.name);
fscanf(fp[1],"%d %d %d %d",&dm,
&st.sub.mat,
&st.sub.eng,
&st.sub.phy);

st=InputStudentData2(st.no,st.name,dm,st.sub.mat,st.sub.eng,
st[i].sub.phy); //←incompatible types when assigning to type ‘SCORE’ from type ‘int’
}

for(i=0;i<4;i++)
fclose(fp[i]);

return 0;

}

アバター
びす
記事: 31
登録日時: 14年前

Re: C

#2

投稿記事 by びす » 13年前

パッと見ですが InputStudentData2の引数を
int st.no, char st.name[],… ではなく
int no, char name[],… とすればいいと思います

non
記事: 1097
登録日時: 15年前

Re: C

#3

投稿記事 by non » 13年前

InputStudentData2という関数は何をやりたいのか説明してください。
この関数の目的が知りたい。
non

アバター
みけCAT
記事: 6734
登録日時: 15年前
住所: 千葉県
連絡を取る:

Re: C

#4

投稿記事 by みけCAT » 13年前

コードはcodeタグで囲んでいただけるとありがたいです。
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

閉鎖

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