1

I am trying an example from the GNU C Programming Tutorial (page 93) that uses a few of the math library routines listed.

#include <stdio.h>
#include <math.h>

int main() {
  double my_pi;

  my_pi = 4 * atan(1.0);

  /* Print the value of pi, to 32 digits */
  printf("my_pi = %.32f\n", my_pi);

  /* Print value of pi from math library, to 32 digits */
  printf("M_PI = %.32f\n", M_PI);

  return 0;
}

When I compile the file 'main.c' using MinGw using the command,

gcc main.c -o main -lm

It gives the following error:

main.c:16:9: error: stray '\32' in program

   16 :      }

      :       ^
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sagar_02
  • 69
  • 6
  • Looks like there is a space following the closing brace - but I have no idea why the compiler would complain about it. White characters at end of line are not forbidden or even discouraged in C. – CiaPan Jun 27 '20 at 15:21
  • 3
    @CiaPan It's an octal 32, not a decimal 32 (SPACE). Probably some UTF-8 character crept in. – Jens Jun 27 '20 at 17:21
  • @Jens Wow, what a stupid mistake. :( Of course it is octal! So the decimal value is 26, which is ASCII EOF or ^Z. This may result from copying or saving the source code with some old-fashioned (DOS-like?) text tool. – CiaPan Jun 27 '20 at 17:31
  • 1
    Does this answer your question? [Stray "\303" and stray "\215" in program -- why?](https://stackoverflow.com/questions/22384338/stray-303-and-stray-215-in-program-why) – Ulrich Eckhardt Jun 28 '20 at 09:00
  • 32 octal = 26 decimal = 0x1A (hexadecimal) = [ASCII SS/SUB](https://en.wikipedia.org/wiki/ASCII#Control_code_chart) AKA `Ctrl + Z`. – Peter Mortensen May 03 '23 at 20:51

2 Answers2

2

The error occurred because of using Turbo C to edit 'main.c' which adds a → character at the end of the curly brackets. That is why compilation fails in MinGW...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sagar_02
  • 69
  • 6
0

The code \32 is an ASCII control character ^Z aka EOF - the End-Of-File (see https://en.wikipedia.org/wiki/End-of-file#EOF_character). It was appended at the end of the text file with some (DOS-like?) editing tool – or maybe you copied a source code and pasted it through some shell command to a file, which resulted in appending the EOF byte.

Try using some other editing tool to strip the last byte from your main.c file. Maybe adding a newline after the closing bracket would be good start.

CiaPan
  • 9,381
  • 2
  • 21
  • 35