我们必须在“结构化编程”(Ansi C) 中准备一个有关 C 在 Visual Studio 中的使用的演示文稿。我已经找到了如何制作 C 文件并使用 C++ 编译器来运行它,但仍然存在一些问题,我还没有找到 awnser。
例如:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(void){
srand((unsigned int)time(NULL)); //seed for random number..
unsigned int ran = rand();
printf("Helloooo World");
printf("%u",ran);
getchar();
return 0;
}
在 Linux 上用 vim 就可以了。但使用 Visual Studio 我收到错误: http://www.pic-upload.de/view-25860939/Capture.jpg.html
- 我的随机种子有问题。
- rand() 函数出现问题。
我认为这是因为我包含的函数,现在我的问题是 Visual Studio 拥有哪些 C 函数,或者我必须更改什么才能使我的程序在 Visual Studio 中运行?
我真的很高兴阅读一些答案。我希望我没有愚蠢地在这里找到答案..:'D
最佳答案
尝试:
include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(void){
unsigned int ran;//<--- Declare ran here.
srand((unsigned int)time(NULL)); //seed for random number..
ran = rand(); ////<--- Use ran here (as before).
printf("Helloooo World");
printf("%u",ran);
getchar();
return 0;
}
Visual Studio 2012 尚不支持 C99。我的意思是这只是 12 年前!!!
编译 C 时,必须在函数开头声明变量。
我知道!嘘!
关于Visual Studio 2012 中的 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27978692/