ページ 11

Posted: 2012年2月07日(火) 01:36
by ニロ
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;

}

Re: C

Posted: 2012年2月07日(火) 03:54
by びす
パッと見ですが InputStudentData2の引数を
int st.no, char st.name[],… ではなく
int no, char name[],… とすればいいと思います

Re: C

Posted: 2012年2月07日(火) 08:37
by non
InputStudentData2という関数は何をやりたいのか説明してください。
この関数の目的が知りたい。

Re: C

Posted: 2012年2月07日(火) 21:16
by みけCAT
コードはcodeタグで囲んでいただけるとありがたいです。