我正在尝试用C编写一个程序,但是我遇到了一个无法编译的函数。该函数被设计为随机生成两个整数作为结构数组的独立部分,我可以告诉它,它工作正常,它只是不会编译。 我得到的错误是第一个'}' 错误:预期标识符或'(' 这是实际的功能代码。我很感激任何帮助。
struct nost * rnote(int measueres, int measuretime);
{
int lengths[16*measures];
int n = 0;
for(int z = 0; z < measures; z++)
{
srand(time(NULL));
float one = 0;
float num = 0;
do
{
num = rand()%100 //makes sure the number is 1-100
if(num < 5){ num = 1/1} //5% chance of whole note
else { if (num < 15) {num = 1/2;} //10% chance of half note
else { if(num < 45) {num = 1/4;} //30%chance of quarter note
else{ if(num < 65) { num = 1/8;} //20% chance of eigth note
else{ if( num < 80) {num = 1/16;} //15%chance of sixteenth note
else{ if(num < 90) { num = 3/4 ;} //10% chance of dotted half
else{ num = 3/8;}}}}}} //10% chance of dotted quarter
//however, because a measure can only have so many beats,
//smaler note engths will end up more likely to happen at
//at the end of the measure
if((one + num) <= measuretime) // makes sure that there are not too many beats in one measure
{
one = one+num;
lengths[n] = num;
n++; //moves n up one so that next lenght is in next spot of array
}
}while(one != measuretime);
}
int arraylength = n; // takes size of lentgh ^^^^ array and puts it in
// the note array
int notes[arraylength]; //the actual notes
for(int y = 0; y < arraylength; y++)
{
srand(time(NULL));
int x = rand()%100;
if(x < 17){ x = 1;} // makes it more likely by 17:8 odds for 1,3,5,8 in scale to appear
else { if (x < 34) {x = 3;} /// than for 2,4,6,7 to appear
else { if(x < 51) {x = 5;}
else{ if(x < 68) { x = 8;}
else{ if( x < 76) {x = 2;}
else{ if(x < 84) { x = 4;}
else{ if(x < 92) { x = 6;}
else{ x = 7;}}}}}}}
notes[y] = x;
}
static struct nost all[1024];
for(int u = 0; u < arraylength; u++)
{
all[u].note = notes[u];
all[u].length = lengths[u];
}
all[0].arraylength = arraylength;
return all;
}
答案 0 :(得分:2)
看起来你开始使用以下功能:
struct nost * rnote(int measueres, int measuretime); { [....]
Extra Semi-Colon Before Body ~~~^