strange errors compiling c code [closed] - c

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.

Related

Compilation Fails Due to Strange Characters Appearing in Source Code

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 “.

C programs are not compiled in my kali linux [closed]

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.

C code using libxml2 giving compile time errors on cygwin on Win 7 [closed]

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 am trying to write a xml parser in C using the libxml2 on cygwin on my Win 7 machine.
When i am trying to compile the code it is giving me compile time errors. Can someone help me out on this.
ad#ad-PC /cygdrive/c/Users/ad/Desktop
$ gcc xmlparser.c -I /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/ -L /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/lib/libxml2.lib -o pxml
In file included from /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/parser.h:807,
from xmlparser.c:8:
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:28:19: iconv.h: No such file or directory
In file included from /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/parser.h:807,
from xmlparser.c:8:
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:146: error: parse error before "iconv_t"
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:146: warning: no semicolon at end of struct or union
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:147: warning: data definition has no type or storage class
xmlparser.c: In function `main':
xmlparser.c:21: error: `filename' undeclared (first use in this function)
xmlparser.c:21: error: (Each undeclared identifier is reported only once
xmlparser.c:21: error: for each function it appears in.)
xmlparser.c:29: error: parse error before ')' token
xmlparser.c: At top level:
xmlparser.c:34: error: parse error before string constant
xmlparser.c:34: error: conflicting types for 'printf'
xmlparser.c:34: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
xmlparser.c:34: error: conflicting types for 'printf'
xmlparser.c:34: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
xmlparser.c:34: warning: data definition has no type or storage class
The code ::
# include <stdio.h>
# include <stdlib.h>
# include <libxml/parser.h>
int main(int argc, char **argv)
{
xmlDoc *document;
xmlNode *root , *node , *first_child;
if(argc < 2)
{
printf("\n Error No filename specified \n");
return 1;
}
filename = argv[1];
document = xmlReadFile(filename,NULL,0);
root = xmlDocGetRootElement(document);
printf("\n Root is ::%s:: <%i> \n",root->name,root->type);
first_child = root->children;
for(node = first_child;node,node = node->next)
{
printf("\n Child is ::%s:: <%i> \n",node -> name, node->type);
}
printf("\n END \n");
return 0;
}
The error message says it unambiguously that filename is not declared and yet you're trying to use it here:
filename = argv[1];
There's also a wrong punctuator here:
for(node = first_child;node,node = node->next)
It has to be ; instead of ,.

Why my .c coding can't be compile in GCC?

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

porting C compilation from MinGW to VisualStudio(nmake)

My current job at the university is to port a C program from MinGW (windows) to Visual Studio (nmake).
I have got a valid "makefile.vc" file for a very similar C program.
My approach was to adopt the Makefile (i.e. "makefile.vc") to the program I need to port.
All but four C files seem to compile fine. Those four files have various errors for example, syntax errors and "unknown size".
Should I continue with my approach to change the Makefile or use CMAKE instead of nmake?
Is there a tutorial or any other pointer on porting a C program from MinGW/gcc to nmake?
typedef struct {
A_TypeConverter *converter;
char *domain;
} enumeratorConverterEntry;
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
error:
f.c(186) : error C2133: 'enumeratorConverterEntries' : unknown size
typedef struct AsmInstructionInfo {
int flags;
CONST char **argTypes; /* line 7 */
int minArgs;
int maxArgs;
int cArgs;
} AsmInstructionInfo;
error:
fAssemble.c(7) : error C2061: syntax error : identifier 'CONST'
..
/* file fStack.c: */
#ifdef CHECK_ACTIVATION_COUNTS
/* code */
#endif
/* more code */
void fShowStack(l_Interp *interp) { /* line 94 */
l_CallFrame *framePtr;
/* more code */
error:
fStack.c(94) : error C2143: syntax error : missing ')' before '*'
fStack.c(94) : error C2143: syntax error : missing '{' before '*'
fStack.c(94) : error C2059: syntax error : ')'
fStack.c(94) : error C2054: expected '(' to follow 'interp'
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
That looks like a valid incomplete, forward declaration of an array, which would be valid syntax, except I think for the static qualifier. I don't have a copy of the 'C' standard in front of me, but reading between the lines on the results of Googling "forward declaration of static array" seems to indicate that an incomplete definition of a static array results in undefined behavior, so Microsoft and GNU are legitimately entitled to do whatever they want with it. GNU accepts it, and Microsoft rejects it. As Mark Wilkins points out you should be make the Microsoft compiler happy by replacing it with:
extern enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
In general it's worth noting that the Microsoft compiler only supports the C89 standard, while the GNU compiler supports portions of the C99 standard, and several of their own extensions, depending on the arguments to the compiler.
The errors in fAssemble.c and fStack.c look like one or more preprocessor files are missing or incomplete. You should search your source to find out where CONST and l_Interp are defined, and then figure out why they are not being picked up in the files where the errors are occurring.
I just now tried out that array declaration with MinGW, and it does compile. To make it link, though, it needs the array to be defined elsewhere. The result is that it appears to be the same as the extern storage class:
extern enumeratorConverterEntry enumeratorConverterEntries[];
I'm not sure if there are other subtleties associated with the original declaration using a static storage class for the global.

Resources