Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        4年前关闭。
                                                                                            
                
        
我们必须在“结构化编程”(Ansi C)中准备一个有关Visual Studio中C用法的演示文稿。我已经找到了如何制作C文件并使用C ++编译器运行它的方法,但是在还没有找到遮阳篷的地方还有一些问题。

例如:

#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;
}


在带有vim的Linux上可以正常工作。但是使用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时,必须在函数开始时声明变量。

我知道!嘘!

关于c - Visual Studio 2012中的C语言,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27978692/

10-13 08:00
查看更多