I've been learning C++, and I was just starting with C, but I got this weird problem which was stopping my compiler from compiling. There were several stray '\342' and whatever errors.
Well, I now know that those are caused by using non-ASCII characters, but the solution to the rest of the posts were very simple. They were using different "" signs because they got the code through copy paste.
I just wrote both this "int main"s (I commented one block or another to test the code... also don't mind the Portuguese. It isn't relevant at all):
#include <stdio.h>
#include <stdlib.h>
/*
int main()
{
float x;
printf("Introduza um numero com bastantes casas decimais: \n");
scanf("%f", &x);
printf("Com 2 casas decimais: %.2f \nCom todas as casas decimais %f", x, x);
return 0;
}
*/
int main()
{
float var;
printf("Introduza um numero com bastantes casas decimais: \n");
scanf("%f", &var);
printf("Com 2 casas decimais: %.2f \nCom todas as casas decimais: %f", var, var);
}
The first block doesn't work, it gives me this errors:
||=== Build: Debug in ExplicAna (compiler: GNU GCC Compiler) ===|
/home/meneses/Cê/ExplicAna/main.c||In function ‘main’:|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\342’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\201’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\240’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\342’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\201’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\240’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\342’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\201’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\240’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\342’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\201’ in program|
/home/meneses/Cê/ExplicAna/main.c|10|error: stray ‘\240’ in program|
on this line:
printf("Com 2 casas decimais: %f \nCom todas as casas decimais %f", x, x);
I erased that line three times, rewrote it, but nothing. The " looks exactly the same.
I then wrote the other code which is the exactly equal and to my surprise it worked!
What am I missing?
I'm worried because this is my first time compiling C and am afraid it might cause harm again in the future.