-3

I am learning C language. I installed and configurated everything to start coding

But when I try to use ampersand (&) in scanf my program doesn't compile:

scanf("%f", &x);

I am getting this error:

The ampersand () character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

mohiris
  • 50
  • 1
  • 6
  • 2
    Are you sure you're not trying to compile it as some other language instead of C? – Shawn May 31 '20 at 11:21
  • What exactly are you using to compile your code? – Catch22 May 31 '20 at 11:21
  • Where do you enter your C code? This error message is from PowerShell, not from the compiler. – Jozef Izso May 31 '20 at 11:22
  • I am using vscode, configured with MinGW, my file extension is ".cpp" because I am using C++ compiler – mohiris May 31 '20 at 11:26
  • PowerShell finally does support `&` to execute a process in the background... I cannot believe it took 6 versions to get to a lame emulation of a simple 40 year old feature in the unix shells. See this answer for details: https://stackoverflow.com/a/53892094/4593267 – chqrlie May 31 '20 at 12:23

2 Answers2

2

I don't think you have everything installed and configured correctly. The error looks like a PowerShell error, not a C compilation error.

Get a C compiler like MinGW-w64 GCC from http://winlibs.com/ and make sure to compile your C code (there is an example on that website showing you how to compile from the Command Prompt).

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • I am using MinGW on vscode it uses launch.json and tasks.json. I can compile any program that doesn't have an ampersand in it correctly. – mohiris May 31 '20 at 11:25
0

Sorry my bad, I had to change my file extension from .cpp to .c to make it work correctly.

mohiris
  • 50
  • 1
  • 6