7

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:


#include <stdio.h>

int main () {

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

}

The problems are 2:

#Include errors were encountered. Update includePath.

Unable to open source file error code "stdio.h".

For this project I have created a folder, in which there is a folder called .dist and my Main.c file

(I have attached an image to be clearer)

enter image description here

Could anyone tell me how I can solve this problem?

3
  • There is an error in your code scanf ("%d", &age); it needs an &. Commented Oct 8, 2020 at 20:52
  • 1
    Is that an error message from your compiler, or your editor? Commented Oct 8, 2020 at 21:08
  • You're missing some config files, namely c_cpp_properties.json, launch.json and tasks.json. I don't quite remember but I believe that if you install the Microsoft C/C++ extension these will be automatically added, read more in code.visualstudio.com/docs/languages/cpp, Commented Oct 8, 2020 at 21:58

3 Answers 3

4

The error showed in the first picture is due to the incorrect setting of the IntelliSenseMode of the editor. 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>".

Sign up to request clarification or add additional context in comments.

1 Comment

This was my problem on a new M1 Pro. VScode set "clang" as my default compiler but was looking for "gcc" in properties.json. Simply changing the path from clang to gcc resolved the issue. TY!
2

First, go to your C/C++ extension configuration and change your compiler path to gcc.exe

Then change Intellisense mode to windows-gcc-x64

Attached a screenshot for better understanding.

[VS Code

1

Comments

-1

So there are 2 problems here:

1st: In the 7th and 8th line of code you have written "% d" which should be "%d" to define the integer data type.

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. For better understanding attaching image.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.