我在學習結構,分別在.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