简体   繁体   中英

How to run C program in Visual Studio (Mac)

so I am trying to run a C program for the first time using VS and Mac OS Catalina however I get the following error messages when trying to run:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/xxx/Documents/EECS2031/scanf2.c).C/C++(1696)


cannot open source file "stdio.h"C/C++(1696)

I'm using the 'Code Runner' extension in VS to run the C code and I have also installed the following things using homebrew:

xcode-select --install
brew install gcc

I'm not sure what else to do as I am completely new to C, and haven't found any other solutions after searching so I need some help. The c filename has a .c extension as well if that helps.

Here is the C code:

#include <stdio.h>
/*The error is here when I am trying to include this library*/


int sum (int i, int j)
{
  return i+j;           
}


main()
{
  int a, b;
  printf("Please enter two integers separated by a blank: " );

  scanf( "%d %d",  &a, &b);     /* assign value to a b  */

  printf("Entered %d and %d. Sum is %d\n", a, b, sum(a,b));

  return 0;
}

Before trying to compile, the C environment (all the include headers, libraries, etc) has to be installed.

this web page should be of great help to you:

https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm

especially the paragraph:

Installation on Mac OS

If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development environment from Apple's web site and follow the simple installation instructions. 
Once you have Xcode setup, you will be able to use GNU compiler for C/C++.

Xcode is currently available at 

developer.apple.com/technologies/tools/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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