Getting this error when I try to compile... I am new to coding in general so it might be obvious and I'm not seeing it.
My code is:
#include<stdio.h>
int main ()
{
float x[7] = 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8;
int i = 3;
printf ("%.2f \n", x[i 1]);
return 0;
}
It's a super simplistic code that is just supposed to output one number... However every time I try to compile I get this error:
test.c:4:8: error: stray ‘\342’ in program
float x���[7] = 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8;
^
test.c:4:9: error: stray ‘\200’ in program
float x���[7] = 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8;
^
test.c:4:10: error: stray ‘\213’ in program
float x��[7] = 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8;
^
test.c:6:21: error: stray ‘\342’ in program
printf ("%.2f \n", x���[i 1]);
^
test.c:6:22: error: stray ‘\200’ in program
printf ("%.2f \n", x���[i 1]);
^
test.c:6:23: error: stray ‘\213’ in program
printf ("%.2f \n", x��[i 1]);
Any idea what might be causing this? Any suggestions would be appreciated!
Thanks!
CodePudding user response:
You have (presumably) tried to copy and paste your code from another source, and that source text contains one or more instances of an invisible character called a zero-width space. This is not valid in your source code. Your compiler is reporting these characters as the underlying bytes used to represent them: in UTF-8 encoding, the zero-width space is encoded with the bytes 0xe2, 0x80, 0x8b. These are, in turn, represented by the compiler as octal backslash escape sequences, giving the values from your error messages.
(Fixing this does not fix your program. You have another syntax error: you must use braces ({
and }
symbols) to enclose your array data.)
CodePudding user response:
You had missed {
and }
in
float x[7] = 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8;
Corrected Code:
float x[7] = { 23.0, -28.6, 30.2, 29.0, -8.0, -30.0, 27.8 };
Now it will give ans = -8.00