Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
my sample.c program:
#include <stdio.h>
int main()
{
printf(“Hello World!\n”);
return 0;
}
so when I want compile it I see this error :
root#Kali:~/Desktop# x86_64-w64-mingw32-gcc sample.c -o file.exe
sample.c: In function ‘main’:
sample.c:5:2: error: stray ‘\342’ in program
sample.c:5:2: error: stray ‘\200’ in program
sample.c:5:2: error: stray ‘\234’ in program
sample.c:5:12: error: ‘Hello’ undeclared (first use in this function)
sample.c:5:12: note: each undeclared identifier is reported only once for each function it appears in
sample.c:5:18: error: expected ‘)’ before ‘World’
sample.c:5:18: error: stray ‘\’ in program
sample.c:5:18: error: stray ‘\342’ in program
sample.c:5:18: error: stray ‘\200’ in program
sample.c:5:18: error: stray ‘\235’ in program
I can't compile any C format file. Please help me.
This is due to your editor .
” (quotation marks) and " is different and ” is causing error .
Try with " .
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
Try other code editor.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
Here is the first header file (set.h):
#include <ctype.h>
int answer_checker(char ans[]);
Here is the function definition (setA.c):
#include "set.h"
int answer_checker(char ans[]){
char arr[10]={'A','C','D','D','B','C','A','B','D','A'};
int score=0;
for(int i=0;i<10;i++){
if(ans[i]=='N'){}
else if(ans[i]==arr[i]){
score+=4;
}
else{
score-=1;
}
}
if(score<0){
return 0;
}
else{
return score;
}
}
And here is the main function (quiz.c):
#include <stdio.h>
#include "set.h"
int main(void){
int score=0;
char ans[10]={'N'};
printf("Enter answers using only A,B,C,D or N\n");
for(int i=0;i<10;i++){
printf("Enter answer for question %d\t",(++i));
scanf("%c\n", &ans[i]);
}
score = answer_checker(ans);
printf("Your score is %d",score);
}
This is what I type on the terminal:
gcc -c setA.c
gcc -c quiz.c
gcc -o setA.o quiz.o
./a.out
I get the error before ./a.out command.
Complete error message:
Undefined symbols for architecture x86_64:
"_answer_checker", referenced from:
_main in quiz.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried to write the quiz.c function in setA.c and then it worked perfectly. I don't know why it won't happen in different files.
I'm trying to write a simply Hello World program but when attempting to compile with GCC, I receive the following error:
helloworld.c:5:18: error: expected ‘)’ before ‘World’
printf(“Hello World”);
^
helloworld.c:5:18: error: stray ‘\342’ in program
helloworld.c:5:18: error: stray ‘\200’ in program
helloworld.c:5:18: error: stray ‘\235’ in program
Does anyone know why this is?
printf(“Hello World”);
This should be written as -
printf("Hello World");
Straight quotes should be used. Try changing style .
The octal sequence 342 200 234 is the UTF-8 byte sequence for the typographic double quote. See this link.
To fix it, replace it with the regular double quote, i.e. " instead of “.
Hey I am trying to connect to a database using postgres
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
int main(int argc, char* argv[])
{
//Start connection
PGconn* connection = PQconnectdb("host=webcourse.cs.nuim.ie dbname=cs621 sslmode=require user=ggales password=1234");
if (PQstatus(connection) ==CONNECTION_BAD)
{
printf("Connection error\n");
PQfinish(connection);
return -1; //Execution of the program will stop here
}
printf("Connection ok\n");
//End connection
PQfinish(connection);
printf("Disconnected\n");
return 0;
}
And I keep getting this compile error:
main.c: In function ‘main’:
main.c:9:35: warning: missing terminating " character [enabled by default]
main.c:9:2: error: missing terminating " character
main.c:10:2: error: ‘dbname’ undeclared (first use in this function)
main.c:10:2: note: each undeclared identifier is reported only once for each function it appears in
main.c:10:9: error: ‘cs621’ undeclared (first use in this function)
main.c:10:15: error: expected ‘)’ before ‘sslmode’
main.c:10:56: warning: missing terminating " character [enabled by default]
main.c:10:15: error: missing terminating " character
main.c:16:1: error: expected ‘,’ or ‘;’ before ‘}’ token
main.c:16:1: error: expected declaration or statement at end of input
Can anyone see why this is happening?
Thanks.
Your code compiles just fine. If I paste it into x.c I can compile it with no problems:
gcc -I /usr/pgsql-9.2/include -L /usr/pgsql-9.2/lib x.c -lpq
(paths may differ on your system).
you may use the 64-bit libpq.lib in a 32-bit program.
you can use a 32-bit libpq.lib or change you platform to x64.
a 32-bit client + 64-bit server can not work well.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have the code below I am trying to build
#include stdio.h
#include stdlib.h
#include signal.h
#include wiringPi.h
#include softPwm.h
void control_event(int sig);
int HARD_PWM_PIN=1; Hardware PWM Pin(GPIO18-12)
int SOFT_PWM_PIN=0; Software PWM Pin(GPIO0-11)
int DELAY_MS=10;
int main(void)
{
(void)signal(SIGINT,control_event);
(void)signal (SIGQUIT,control_event);
printf(Hardware and software based PWM test on LEDn);
if(getuid()!=0) wiringPi requires root privileges
{
printf(ErrorwiringPi must be run as root.n);
return 1;
}
if(wiringPiSetup()==-1)
{
printf(ErrorwiringPi setup failed.n);
return 1;
}
pinMode(HARD_PWM_PIN,PWM_OUTPUT); setup hardware pwm
softPwmCreate(SOFT_PWM_PIN,0,100); setup software pwm pin
int up;
int down;
while(1)
{
for(up=1;up=5;down--)
{
pwmWrite(HARD_PWM_PIN,down);
softPwmWrite(SOFT_PWM_PIN,down);
delay(DELAY_MS2);
}
delay(DELAY_MS5);
}
}
void control_event(int sig)
{
printf(bbExiting...n);
pwmWrite(HARD_PWM_PIN,0);
softPwmWrite(SOFT_PWM_PIN,0);
delay(100); wait a little for the pwm to finish write
exit(0);
}
But I keep getting the following errors this is only a portion of them but they are pretty much the same throughout with the odd symbols and numbers.
test1.c:20:1: error: stray â\302â in program
test1.c:20:1: error: stray â\240â in program
test1.c:21:1: error: stray â\302â in program
test1.c:21:1: error: stray â\240â in program
test1.c:22:1: error: stray â\302â in program
test1.c:22:1: error: stray â\240â in program
test1.c:23:1: error: stray â\302â in program
test1.c:23:1: error: stray â\240â in program
test1.c:23:1: error: stray â\302â in program
test1.c:23:1: error: stray â\240â in program
test1.c:24:1: error: stray â\302â in program
test1.c:24:1: error: stray â\240â in program
test1.c:24:1: error: stray â\302â in program
test1.c:24:1: error: stray â\240â in program
test1.c:25:1: error: stray â\302â in program
test1.c:25:1: error: stray â\240â in program
test1.c:26:1: error: stray â\302â in program
test1.c:26:1: error: stray â\240â in program
test1.c:26:38: error: unknown type name âsetupâ
test1.c:26:53: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âpwmâ
What could be wrong? The place I am getting this code from is here
You have some syntax errors -
aside from that your editor included unicode characters instead of the ASCII expected by gcc. - a possible example for " as a backward double quote or forward double quote instead of ASCII 34.
You have to be careful about your editor settings when you are using a non-western character set or extended unicode as your default encoding.
This is also why " characters do not show up in your post.
The odd symbols and numbers are because some of the spaces in the file aren't actually spaces. Looking at some of the lines in the file in your link, after copying and pasting:
'void control_event(int sig);\n'
'int HARD_PWM_PIN=1; //Hardware PWM Pin(GPIO18-12)\n'
'int SOFT_PWM_PIN=0; //Software PWM Pin(GPIO0-11)\n'
'int DELAY_MS=10;\n'
'int main(void)\n'
'{\n'
'\xc2\xa0 (void)signal(SIGINT,control_event);\n'
'\xc2\xa0 (void)signal (SIGQUIT,control_event);\n'
'\xc2\xa0 printf("Hardware and software based PWM test on LED\\n");\n'
'\xc2\xa0 if(getuid()!=0) //wiringPi requires root privileges\n'
Those \xc2\xa0s are the non-breaking space characters ( ), or 302/240 in octal.
Also note that you seem to have lost several comment markers (//) in transit, which is causing different problems of its own as the compiler is trying to interpret comments as code.
I have a simple code in c :
#include <stdio.h>
main()
{
printf(“Hello, world! /n”);
}
but I can't compile it in GCC. The warning when i try to compile it :
1. gcc hello.c -o hello
2. hello.c: In function 'main:
3. hello.c:4:1: error: stray '\342' in program
4. hello.c:4:1: error: stray '\200' in program
5. hello.c:4:1: error: stray '\234' in program
6. hello.c:4:11: error: 'Hello' undeclared (first use in this function)
7. hello.c:4:11: note: each undeclared identifier is reported only once for each function
it appears in
8. hello.c:4:18: error: 'world' undeclared (first use in this function)
9. hello.c:4:23: error: expected ')' before '!' token
10. hello.c:4:23: error: stray '\342' in program
11. hello.c:4:23: error: stray '\200' in program
12. hello.c:4:23: error: stray '\235' in program
anyone can help me please?
You get those errors because you presumably copy and pasted that code from a formatted source. “ and ” aren't the same as ". Change them to that and the code will compile.
You should probably also follow the convention of having main defined as:
int main(void)
and therefore returning an int.
You probably also want to change /n to \n