我在学习结构,分别在.h和.c文件中有下面的代码。结构不编译?
typedef struct{
int lengthOfSong;
int yearRecorded;
} Song;
Song makeSong (int length, int year);
void displaySong(Song theSong);
.C:
Song makeSong(int length, int year){
Song newSong;
newSong.lengthOfSong = length;
newSong.yearRecorded = year;
displaySong(newSong);
return newSong;
}
void displaySong(Song theSong){
printf("This is the length of the song: %i \n This is the year recorded: %i", theSong.lengthOfSong, theSong.yearRecorded);
}
出于某种原因,我发现了错误:song.c:1:错误:预期 '=', '', ';',“ASM '或' “前 'makeSong' song.c:11:错误:预期 '属性)theSong '
我是不是做错了什么' 前'?
编辑主(其他功能已经工作):
#include <stdio.h>
#include "math_functions.h"
#include "song.h"
main(){
int differ = difference(10, 5);
int thesum = sum(3, 7);
printf("differnece: %i, sum: %i \n", differ, thesum);
Song theSong = makeSong(5, 8);
}
难道你'#包括 “song.h”'? – 2011-03-24 21:55:36
是的。见上面的主要部分。 (已编辑) – locoboy 2011-03-24 21:59:09
您是否在.c文件中包含'#include“song.h”',其中包含'宋makeSong(int length,int year){'?根据编译器的错误信息,看起来不是,因为引用的行是第一行。 – Vlad 2011-03-24 22:04:14