PDA

View Full Version : [SOLVED] Begining linux programing 3rd edition



checoimg
September 5th, 2012, 09:05 PM
I'm making an exercise and I get an error.


zahory@frogui:~/C programming$ gcc -c bill.c fred.c
bill.c: In function ‘bill’:
bill.c:4:2: error: stray ‘\342’ in program
bill.c:4:2: error: stray ‘\200’ in program
bill.c:4:2: error: stray ‘\234’ in program
bill.c:4:16: error: expected ‘)’ before ‘:’ token
bill.c:4:16: error: stray ‘\’ in program
bill.c:4:16: error: stray ‘\342’ in program
bill.c:4:16: error: stray ‘\200’ in program
bill.c:4:16: error: stray ‘\235’ in program
bill.c:4:16: warning: passing argument 1 of ‘printf’ from incompatible pointer type [enabled by default]
/usr/include/stdio.h:363:12: note: expected ‘const char * __restrict__’ but argument is of type ‘void (*)(char *)’
bill.c:4:16: warning: format not a string literal and no format arguments [-Wformat-security]
fred.c: In function ‘fred’:
fred.c:4:2: error: stray ‘\342’ in program
fred.c:4:2: error: stray ‘\200’ in program
fred.c:4:2: error: stray ‘\234’ in program
fred.c:4:16: error: expected ‘)’ before ‘:’ token
fred.c:4:16: error: stray ‘\’ in program
fred.c:4:16: error: stray ‘\342’ in program
fred.c:4:16: error: stray ‘\200’ in program
fred.c:4:16: error: stray ‘\235’ in program
fred.c:4:16: warning: passing argument 1 of ‘printf’ from incompatible pointer type [enabled by default]
/usr/include/stdio.h:363:12: note: expected ‘const char * __restrict__’ but argument is of type ‘void (*)(int)’
fred.c:4:16: warning: format not a string literal and no format arguments [-Wformat-security]

durdenstationer
September 5th, 2012, 09:22 PM
Post the code.

checoimg
September 5th, 2012, 09:27 PM
Post the code.

this id fred.c :



#include <stdio.h>
void fred(int arg)
{
printf(“fred: you passed %d\n”, arg);
}


and this is bill.c :



#include <stdio.h>
void bill(char *arg)
{
printf(“bill: you passed %s\n”, arg);
}

durdenstationer
September 5th, 2012, 09:30 PM
Compiles fine as copied from your post. I googled your errors, though, and it has to do with your quotation marks in your original source file. Replace them with neutral quotations instead of left and right quotations.

durdenstationer
September 5th, 2012, 09:39 PM
To explain further, you're feeding non-ASCII characters to the compiler with the smart quotes and it can't interpret them. Did you copy-and-paste the code?

checoimg
September 5th, 2012, 09:39 PM
Compiles fine as copied from your post. I googled your errors, though, and it has to do with your quotation marks in your original source file. Replace them with neutral quotations instead of left and right quotations.

Do you mean ?

printf('bill: you passed %s\n', arg)

checoimg
September 5th, 2012, 09:40 PM
To explain further, you're feeding non-ASCII characters to the compiler with the smart quotes and it can't interpret them. Did you copy-and-paste the code?

Yes I copied the code

Odexios
September 5th, 2012, 09:41 PM
What text editor are you using?

durdenstationer
September 5th, 2012, 09:43 PM
Do you mean ?

printf('bill: you passed %s\n', arg)

No. Single quotes are for character literals. Use neutral double quotes since your copied code was using left and right handed double quotes.

papibe
September 5th, 2012, 09:48 PM
Hi checoimg.

I think the copy/paste process screwed up your double quotes. Read this (http://www.giannistsakiris.com/index.php/2008/04/17/gcc-error-stray-%E2%80%98342%E2%80%99-in-program/).

Regards.

checoimg
September 5th, 2012, 09:51 PM
Thank you everyone for your attention, the problem was that I copied the code I just compiled it and worked fine.

checoimg
September 5th, 2012, 09:52 PM
What text editor are you using?

gedit

lisati
September 5th, 2012, 09:53 PM
Hi checoimg.

I think the copy/paste process screwed up your double quotes. Read this (http://www.giannistsakiris.com/index.php/2008/04/17/gcc-error-stray-%E2%80%98342%E2%80%99-in-program/).

Regards.

+1

I've also added
and tags (http://ubuntuforums.org/misc.php?do=bbcode) to post 3 (http://ubuntuforums.org/showpost.php?p=12219916&postcount=3) of this thread, which can help us see what's going on.

durdenstationer
September 5th, 2012, 09:56 PM
Look into gedit snippets to autoconvert the quotes when pasting so it converts smart quotes to neutral quotes.