Visual Studio 2012 中的 C

标签 c visual-studio visual-studio-2012 ansi-c

我们必须在“结构化编程”(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

  1. 我的随机种子有问题。
  2. 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/

相关文章:

C结构语法

c - 通过恰好更改一个字符来修复损坏的循环

C 结构不扫描所有输入

android - 尝试从 Android 模拟器访问本地托管的 ASP.net 服务 - 未在 127.0.0.1 上公开?

c# - 模拟测试方法

visual-studio - VS 2012 和 TFS 2010 的 checkin 策略错误 - CheckForWarningsPolicy

c++ - VS2010 和 VS2012 之间的二进制 C++ 库兼容性?

带有函数的c中的字符数组

c# - 相同的 Excel 公式在 Visual Studio C# 中返回不同的结果

vb.net - VB 注册 Com Interop