简体   繁体   English

#包括<stdio.h>问题(Visual Studio 代码)</stdio.h>

[英]#Include <stdio.h> problem (Visual Studio Code)

I am trying to do a project in C but I have problems with the string #include<stdio.h> , I tried several tutorials but none of them worked, my code:我正在尝试在 C 中做一个项目,但我对字符串#include<stdio.h>有问题,我尝试了几个教程,但都没有奏效,我的代码:


#include <stdio.h>

int main () {

     int age;
     printf ("Enter age:");
     scanf ("% d", age);
     printf ("age is% d", age);
     return 0;

}

The problems are 2:问题是2:

#Include errors were encountered. #Include 遇到错误。 Update includePath.更新包含路径。

Unable to open source file error code "stdio.h".无法打开源文件错误代码“stdio.h”。

For this project I have created a folder, in which there is a folder called.dist and my Main.c file对于这个项目,我创建了一个文件夹,其中有一个名为.dist 的文件夹和我的 Main.c 文件

(I have attached an image to be clearer) (为了更清楚,我附上了一张图片)

在此处输入图像描述

Could anyone tell me how I can solve this problem?谁能告诉我如何解决这个问题?

Thank you very much for all the advice, I added the files c_cpp_proprietes.json , launch.json , task.json and I added the Microsoft C / C ++ extension, I also fixed the code, but the problem remains before, also because I don't know what code I have to put in the files that I added maybe?非常感谢您的所有建议,我添加了文件c_cpp_proprietes.jsonlaunch.jsontask.json并添加了 Microsoft C / C ++ 扩展名,我还修复了代码,但问题仍然存在,也是因为我不知道我必须在我添加的文件中放入什么代码? 在此处输入图像描述

The error showed in the first picture is due to the incorrect setting of the IntelliSenseMode of the editor.第一张图片显示的错误是由于编辑器的IntelliSenseMode设置不正确。 I bet that you have installed gcc compiler on your computer and you should also set "gcc" on the IntelliSenseMode of the editor which, by default, has a wrong value that freakout when it reads "#include <stdio.h>".我敢打赌,你已经在你的计算机上安装了 gcc 编译器,你还应该在编辑器的 IntelliSenseMode 上设置“gcc”,默认情况下,它的值错误,当它读取“#include <stdio.h>”时会崩溃。

First, go to your C/C++ extension configuration and change your compiler path to gcc.exe首先,将 go 更改为 C/C++ 扩展配置并将编译器路径更改为gcc.exe

Then change Intellisense mode to windows-gcc-x64然后将 Intellisense 模式更改为windows-gcc-x64

Attached a screenshot for better understanding.附上截图以便更好理解。

VS Code VS 代码

So there are 2 problems here:所以这里有2个问题:

1st: In the 7th and 8th line of code you have written "% d" which should be "%d" to define the integer data type.第一:在第 7 行和第 8 行代码中,您编写了“%d”,它应该是“%d”来定义整数数据类型。

2nd: Again in the 7th line of code you forgot to put "&" before the variable "age" which provides the address of the variable to put the entered value.第二:再次在第 7 行代码中,您忘记在变量“age”之前放置“&”,该变量提供了放置输入值的变量地址。 For better understanding attaching image.为了更好地理解附加图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM