hidden characters in source code causing compiler grief

I believe somehow I got some hidden characters in my source file that
is causing it to not compile. I think they got in there by Word
Processor formatting codes or perhaps when I got the code from a
friend via email. Any easy way to see if they are in there, like a
turn on hidden characters or something?

Advertisements

Guest

On Apr 8, 4:58 pm, Gary <> wrote:
> I believe somehow I got some hidden characters in my source file that
> is causing it to not compile. I think they got in there by Word
> Processor formatting codes or perhaps when I got the code from a
> friend via email. Any easy way to see if they are in there, like a
> turn on hidden characters or something?

Without knowing what editor you are using, it's pretty difficult to
tell you how to get it to show you non-printing characters.

Can you tell us exactly what errors you are getting from your
compiler?

Advertisements

Gary wrote:
> I believe somehow I got some hidden characters in my source file that
> is causing it to not compile. I think they got in there by Word
> Processor formatting codes or perhaps when I got the code from a
> friend via email. Any easy way to see if they are in there, like a
> turn on hidden characters or something?

This is really a topic about the tools available on your system, and I
have no idea what those are. Many moons ago I used edt, and I'm sure
that would do the job, but I doubt you have it. vim or emacs could
probably do it as well. For the future, I would advice you to use wor
processors for word processing and text editors for editing text!

Also, I would advise you to ask in a group or mailing list dedicated to
whatever editor you like using or, alternatively, a group dedicated to
programming on your OS about what useful tools are available.

Of you could write a C program to scan the file, for which the isprint()
function might well be useful.
--
Flash Gordon

On Apr 8, 3:27 pm, wrote:
> On Apr 8, 4:58 pm, Gary <> wrote:
>
> > I believe somehow I got some hidden characters in my source file that
> > is causing it to not compile. I think they got in there by Word
> > Processor formatting codes or perhaps when I got the code from a
> > friend via email. Any easy way to see if they are in there, like a
> > turn on hidden characters or something?
>
> Without knowing what editor you are using, it's pretty difficult to
> tell you how to get it to show you non-printing characters.
>
> Can you tell us exactly what errors you are getting from your
> compiler?

Thanks.. I am trying to help a neighbors kid. He and myself are both
on Ubuntu. So I was trying to help him a little bit with his homework.
I think he may have used Open Office Word, or when I emailed him back,
he may have cut and paste it from email or something.

I used both the Text Editor in Ubuntu and vi (vim) from the shell. I
can't see any characters, but when I delete some lines, and re-type
some of the code in as I see it, some of the errors go away.

vlsidesign wrote:
> On Apr 8, 3:27 pm, wrote:
> > On Apr 8, 4:58 pm, Gary <> wrote:
> >
> > > I believe somehow I got some hidden characters in my source file that
> > > is causing it to not compile. I think they got in there by Word
> > > Processor formatting codes or perhaps when I got the code from a
> > > friend via email. Any easy way to see if they are in there, like a
> > > turn on hidden characters or something?
> >
> > Without knowing what editor you are using, it's pretty difficult to
> > tell you how to get it to show you non-printing characters.
....
> Thanks.. I am trying to help a neighbors kid. He and myself are both
> on Ubuntu.

On most Unix-like systems, you can use the command "od -c filename" to
get a dump of the file where non-ASCII characters are displayed as
escape sequences.

On Apr 8, 4:32 pm, jameskuyper <> wrote:
> vlsidesign wrote:
> > On Apr 8, 3:27 pm, wrote:
> > > On Apr 8, 4:58 pm, Gary <> wrote:
>
> > > > I believe somehow I got some hidden characters in my source file that
> > > > is causing it to not compile. I think they got in there by Word
> > > > Processor formatting codes or perhaps when I got the code from a
> > > > friend via email. Any easy way to see if they are in there, like a
> > > > turn on hidden characters or something?
>
> > > Without knowing what editor you are using, it's pretty difficult to
> > > tell you how to get it to show you non-printing characters.
> ...
> > Thanks.. I am trying to help a neighbors kid. He and myself are both
> > on Ubuntu.
>
> On most Unix-like systems, you can use the command "od -c filename" to
> get a dump of the file where non-ASCII characters are displayed as
> escape sequences.

On Apr 8, 4:32 pm, jameskuyper <> wrote:
> vlsidesign wrote:
> > On Apr 8, 3:27 pm, wrote:
> > > On Apr 8, 4:58 pm, Gary <> wrote:
>
> > > > I believe somehow I got some hidden characters in my source file that
> > > > is causing it to not compile. I think they got in there by Word
> > > > Processor formatting codes or perhaps when I got the code from a
> > > > friend via email. Any easy way to see if they are in there, like a
> > > > turn on hidden characters or something?
>
> > > Without knowing what editor you are using, it's pretty difficult to
> > > tell you how to get it to show you non-printing characters.
> ...
> > Thanks.. I am trying to help a neighbors kid. He and myself are both
> > on Ubuntu.
>
> On most Unix-like systems, you can use the command "od -c filename" to
> get a dump of the file where non-ASCII characters are displayed as
> escape sequences.

On Wed, 8 Apr 2009 16:25:19 -0700 (PDT), vlsidesign <>
wrote:
>On Apr 8, 3:27 pm, wrote:
>> On Apr 8, 4:58 pm, Gary <> wrote:
>>
>> > I believe somehow I got some hidden characters in my source file that
>> > is causing it to not compile. I think they got in there by Word
>> > Processor formatting codes or perhaps when I got the code from a
>> > friend via email. Any easy way to see if they are in there, like a
>> > turn on hidden characters or something?
>>
>> Without knowing what editor you are using, it's pretty difficult to
>> tell you how to get it to show you non-printing characters.
>>
>> Can you tell us exactly what errors you are getting from your
>> compiler?
>
>Thanks.. I am trying to help a neighbors kid. He and myself are both
>on Ubuntu. So I was trying to help him a little bit with his homework.
>I think he may have used Open Office Word, or when I emailed him back,
>he may have cut and paste it from email or something.
>
>I used both the Text Editor in Ubuntu and vi (vim) from the shell. I
>can't see any characters, but when I delete some lines, and re-type
>some of the code in as I see it, some of the errors go away.
>
>Here are snapshot of the errors before my mods:
>
>prime2.c:3:9: error: #include expects "FILENAME" or <FILENAME>
>prime2.c:4:9: error: #include expects "FILENAME" or <FILENAME>
>prime2.c:5: error: stray ‘\302’ in program
>prime2.c:5: error: stray ‘\240’ in program
>prime2.c: In function ‘main’:
>prime2.c:7: error: stray ‘\302’ in program
>prime2.c:7: error: stray ‘\240’ in program
>prime2.c:7: error: stray ‘\302’ in program
[snip...snip...]

Well, to on-topic this for c.l.c, why not write a small filter app that
ingests the suspect files and then reports on (and optionally deletes)
any characters that aren't in the standard character set. Perhaps a
combination of isprint() and iscntrl()?

On Apr 8, 6:25 pm, vlsidesign <> wrote:
> On Apr 8, 3:27 pm, wrote:
>
> > On Apr 8, 4:58 pm, Gary <> wrote:
>
> > > I believe somehow I got some hidden characters in my source file that
> > > is causing it to not compile. I think they got in there by Word
> > > Processor formatting codes or perhaps when I got the code from a
> > > friend via email. Any easy way to see if they are in there, like a
> > > turn on hidden characters or something?
>
> > Without knowing what editor you are using, it's pretty difficult to
> > tell you how to get it to show you non-printing characters.
>
> > Can you tell us exactly what errors you are getting from your
> > compiler?
>
> Thanks.. I am trying to help a neighbors kid. He and myself are both
> on Ubuntu. So I was trying to help him a little bit with his homework.
> I think he may have used Open Office Word, or when I emailed him back,
> he may have cut and paste it from email or something.
>
> I used both the Text Editor in Ubuntu and vi (vim) from the shell. I
> can't see any characters, but when I delete some lines, and re-type
> some of the code in as I see it, some of the errors go away.
>
> Here are snapshot of the errors before my mods:
>
> prime2.c:3:9: error: #include expects "FILENAME" or <FILENAME>
> prime2.c:4:9: error: #include expects "FILENAME" or <FILENAME>
> prime2.c:5: error: stray ‘\302’ in program
> prime2.c:5: error: stray ‘\240’ in program
> prime2.c: In function ‘main’:
> prime2.c:7: error: stray ‘\302’ in program
> prime2.c:7: error: stray ‘\240’ in program
> prime2.c:7: error: stray ‘\302’ in program
> <snip>
>
> I then delete that top two include lines and retype it in and it seems
> to resolve some of the errors and I get:
>
> prime.c:3: error: stray ‘\302’ in program
> prime.c:3: error: stray ‘\240’ in program
> prime.c: In function ‘main’:
> prime.c:5: error: stray ‘\302’ in program
> prime.c:5: error: stray ‘\240’ in program
> prime.c:5: error: stray ‘\302’ in program
> <snip>
>
> Here is the top part of the code:
> #include <stdio.h>
> #include <stdbool.h>
> int main(void)
> {
> int number;
> int d;
> _Bool isPrime; // set to 0 if number is non­prime
> int maxNum;
> printf("Enter max number: ");
> <snip>

man iso_8859-1 identifies \240 as
NO-BREAK SPACE
and \302 as
LATIN CAPITAL LETTER A WITH CIRCUMFLEX

It seems likely that the file passed through the grubby hands of a
word processor. If one must be used, it may be found useful to select
a very primitive "terminal" font. This may help by making non-ASCII
character stick out like a sore thumb.

For that matter, they should stick out in vi. For me, \302 looks like
a lowercase y with 2 dots, and \240 looks like a Russian cursive d.

I don't see either of these on the corresponding snippet. Was it
pasted or retyped?

On Apr 8, 4:53 pm, luserXtrog <> wrote:
> On Apr 8, 6:25 pm, vlsidesign <> wrote:
>
<snip>
>
> man iso_8859-1 identifies \240 as
> NO-BREAK SPACE
> and \302 as
> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>
> It seems likely that the file passed through the grubby hands of a
> word processor. If one must be used, it may be found useful to select
> a very primitive "terminal" font. This may help by making non-ASCII
> character stick out like a sore thumb.
>
> For that matter, they should stick out in vi. For me, \302 looks like
> a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>
> I don't see either of these on the corresponding snippet. Was it
> pasted or retyped?
>

shell$ more prime.c //I more prime.c and then I copy and paste to
below

vlsidesign <> writes:
> On Apr 8, 4:53Â pm, luserXtrog <> wrote:
>> On Apr 8, 6:25Â pm, vlsidesign <> wrote:
>>
> <snip>
>>
>> man iso_8859-1 identifies \240 as
>> NO-BREAK SPACE
>> and \302 as
>> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>>
>> It seems likely that the file passed through the grubby hands of a
>> word processor. If one must be used, it may be found useful to select
>> a very primitive "terminal" font. This may help by making non-ASCII
>> character stick out like a sore thumb.
>>
>> For that matter, they should stick out in vi. For me, \302 looks like
>> a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>>
>> I don't see either of these on the corresponding snippet. Was it
>> pasted or retyped?

My news reader happens to show me all the no-break spaces in that
snippet because I have configured it to, but Ubuntu, being a UTF-8
based system, will probably keep showing you a space.

There are lots of ways to fix this code as a once-off but the key is
to avoid using any tools that can put unusual characters into your
code to start off with. I heard your neighbour used a word processor
to write the program. This is not a good idea. You know what a food
processor does to food, right?

On Apr 8, 7:27 pm, vlsidesign <> wrote:
> On Apr 8, 4:53 pm, luserXtrog <> wrote:
>
>
>
> > On Apr 8, 6:25 pm, vlsidesign <> wrote:
>
> <snip>
>
> > man iso_8859-1 identifies \240 as
> > NO-BREAK SPACE
> > and \302 as
> > LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>
> > It seems likely that the file passed through the grubby hands of a
> > word processor. If one must be used, it may be found useful to select
> > a very primitive "terminal" font. This may help by making non-ASCII
> > character stick out like a sore thumb.
>
> > For that matter, they should stick out in vi. For me, \302 looks like
> > a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>
> > I don't see either of these on the corresponding snippet. Was it
> > pasted or retyped?
>
> shell$ more prime.c //I more prime.c and then I copy and paste to
> below

Right on! I take it back. But do they show in vi? You should
be able to substitute them away :%s/^V302//g :%s/^V240//g
(where ^V is ctrl-V, of course.

On Apr 8, 5:37 pm, Ben Bacarisse <> wrote:
> vlsidesign <> writes:
> > On Apr 8, 4:53 pm, luserXtrog <> wrote:
> >> On Apr 8, 6:25 pm, vlsidesign <> wrote:
>
> > <snip>
>
> >> man iso_8859-1 identifies \240 as
> >> NO-BREAK SPACE
> >> and \302 as
> >> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>
> >> It seems likely that the file passed through the grubby hands of a
> >> word processor. If one must be used, it may be found useful to select
> >> a very primitive "terminal" font. This may help by making non-ASCII
> >> character stick out like a sore thumb.
>
> >> For that matter, they should stick out in vi. For me, \302 looks like
> >> a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>
> >> I don't see either of these on the corresponding snippet. Was it
> >> pasted or retyped?
>
> Many systems will show a space since the combination is the UTF-8
> encoding of a no-breaking space.
>
>
>
> > shell$ more prime.c //I more prime.c and then I copy and paste to
> > below
>
> > #include <stdio.h>
> > #include <stdbool.h>
> > int main(void)
> > {
> > int number;
> > int d;
> > _Bool isPrime; // set to 0 if number is non­prime
> > int maxNum;
> > printf("Enter max number: ");
>
> My news reader happens to show me all the no-break spaces in that
> snippet because I have configured it to, but Ubuntu, being a UTF-8
> based system, will probably keep showing you a space.
>
> There are lots of ways to fix this code as a once-off but the key is
> to avoid using any tools that can put unusual characters into your
> code to start off with. I heard your neighbour used a word processor
> to write the program. This is not a good idea. You know what a food
> processor does to food, right?
>
> --
> Ben.

Good point. I typed some words in text editor and saved it. Then I
typed the same letters in a word processor and then saved it. I then
showed him the size difference of each and explained the word
processor has some hidden formatting type codes, and that sort of
stuff, even though they both look the same.

On Apr 8, 6:00 pm, luserXtrog <> wrote:
> On Apr 8, 7:27 pm, vlsidesign <> wrote:
>
>
>
> > On Apr 8, 4:53 pm, luserXtrog <> wrote:
>
> > > On Apr 8, 6:25 pm, vlsidesign <> wrote:
>
> > <snip>
>
> > > man iso_8859-1 identifies \240 as
> > > NO-BREAK SPACE
> > > and \302 as
> > > LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>
> > > It seems likely that the file passed through the grubby hands of a
> > > word processor. If one must be used, it may be found useful to select
> > > a very primitive "terminal" font. This may help by making non-ASCII
> > > character stick out like a sore thumb.
>
> > > For that matter, they should stick out in vi. For me, \302 looks like
> > > a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>
> > > I don't see either of these on the corresponding snippet. Was it
> > > pasted or retyped?
>
> > shell$ more prime.c //I more prime.c and then I copy and paste to
> > below
>
> Right on! I take it back. But do they show in vi? You should
> be able to substitute them away :%s/^V302//g :%s/^V240//g
> (where ^V is ctrl-V, of course.
>
> --
> laxdroog

vlsidesign <> writes:
> On Apr 8, 6:00 pm, luserXtrog <> wrote:
>> On Apr 8, 7:27 pm, vlsidesign <> wrote:
>>
>>
>>
>> > On Apr 8, 4:53 pm, luserXtrog <> wrote:
>>
>> > > On Apr 8, 6:25 pm, vlsidesign <> wrote:
>>
>> > <snip>
>>
>> > > man iso_8859-1 identifies \240 as
>> > > NO-BREAK SPACE
>> > > and \302 as
>> > > LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>>
>> > > It seems likely that the file passed through the grubby hands of a
>> > > word processor. If one must be used, it may be found useful to select
>> > > a very primitive "terminal" font. This may help by making non-ASCII
>> > > character stick out like a sore thumb.
>>
>> > > For that matter, they should stick out in vi. For me, \302 looks like
>> > > a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>>
>> > > I don't see either of these on the corresponding snippet. Was it
>> > > pasted or retyped?
>>
>> > shell$ more prime.c //I more prime.c and then I copy and paste to
>> > below
>>
>> Right on! I take it back. But do they show in vi? You should
>> be able to substitute them away :%s/^V302//g :%s/^V240//g
>> (where ^V is ctrl-V, of course.
>
> For me, when I am using vi in Ubuntu, I can't see them.

<OT>
env LANG=C vi filename.c

vi's behavior is affected by the current locale settings. Ubuntu's
default is to use UTF-8. Setting the environment variable "LANG" to
"C" changes this behavior, so the two-byte sequence that is the UTF-8
representation of NO-BREAK SPACE is no longer interpreted that way.

See also the "cat -A" or "cat -v" command ("man cat" for details).
</OT>

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

On Apr 8, 6:00 pm, luserXtrog <> wrote:
> On Apr 8, 7:27 pm, vlsidesign <> wrote:
>
>
>
> > On Apr 8, 4:53 pm, luserXtrog <> wrote:
>
> > > On Apr 8, 6:25 pm, vlsidesign <> wrote:
>
> > <snip>
>
> > > man iso_8859-1 identifies \240 as
> > > NO-BREAK SPACE
> > > and \302 as
> > > LATIN CAPITAL LETTER A WITH CIRCUMFLEX
>
> > > It seems likely that the file passed through the grubby hands of a
> > > word processor. If one must be used, it may be found useful to select
> > > a very primitive "terminal" font. This may help by making non-ASCII
> > > character stick out like a sore thumb.
>
> > > For that matter, they should stick out in vi. For me, \302 looks like
> > > a lowercase y with 2 dots, and \240 looks like a Russian cursive d.
>
> > > I don't see either of these on the corresponding snippet. Was it
> > > pasted or retyped?
>
> > shell$ more prime.c //I more prime.c and then I copy and paste to
> > below
>
> Right on! I take it back. But do they show in vi? You should
> be able to substitute them away :%s/^V302//g :%s/^V240//g
> (where ^V is ctrl-V, of course.
>
> --
> laxdroog

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!