我有一个简单的函数,它给我这个错误:
错误:预期的声明说明符或“时间”之前的“...”
这是文件中的代码:
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
float random_number(float min, float max) {
float difference = (max - min);
return (((float)(difference + 1)/RAND_MAX) * rand() + min);
}
我不明白为什么我会收到这个错误。我在 Ubuntu 12.04 中使用 gcc 进行编译。
最佳答案
在C语言中,所有在运行时执行的代码都必须在函数内部。将对 srand()
的调用放在 init 函数中。
关于c - 错误 : expected delcaration specifiers or '...' before 'time' [C],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19846191/