gpt4 book ai didi

c - 由于一个分号,函数无法编译,我不知道为什么

转载 作者:行者123 更新时间:2023-11-30 21:20:06 25 4
gpt4 key购买 nike

我正在尝试用 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;
}

最佳答案

看起来您的函数是这样开始的:

struct nost * rnote(int measueres, int measuretime); { [....]
Extra Semi-Colon Before Body ~~~^

关于c - 由于一个分号,函数无法编译,我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43462512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com