stray '\160' in program

A

Alvin

Right. I`m using Dev-Cpp, and I`m working on a game at this time in SDL
(http://libsdl.org), and I`ve come across this error:

------------------------------------------
main.c: In function `SDL_main':
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program

make.exe: *** [main.o] Error 1

Execution terminated
------------------------------------------

Which halts my entire game development, and I`ve no idea whats wrong.
Here`s the full source:

(it`s messy, because I`ve tried to debug it a lot, ignore the commented
statements and such)

-------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <SDL/SDL.h>
#include "include/SDL_std.h"

SDL_Surface *screen;
SDL_Surface *image;


void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int
y2)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);
}

void patchbg(int x, int y)
{
DrawIMG(image, 0, 0, 50, 50, x-2, y-2);
}

void ShowBMP(char *file, SDL_Surface *screen, int x, int y)
{

SDL_Rect dest;

/* Load the BMP file into a surface */
image = SDL_LoadBMP(file);
if ( image == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n", file,
SDL_GetError());
return;
}

/* Blit onto the screen surface.
The surfaces should not be locked at this point.
*/
dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dest);

/* Update the changed portion of the screen */
SDL_UpdateRects(screen, 1, &dest);
}

void blit_mb(x, y)
{
SDL_Surface *redblock;
redblock = SDL_LoadBMP("data/meatball.bmp");

SDL_Rect source;

source.x = x;

source.y = y;

source.w = 50;

source.h = 50;



SDL_Rect destination;

destination.x = x;

destination.y = y;

destination.w = 50;

destination.h = 50;


SDL_SetColorKey(redblock,SDL_SRCCOLORKEY,SDL_MapRGB(redblock->format,255,255,255));

SDL_BlitSurface(redblock, &source, screen, &destination);
}

int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

SDL_Surface *screen;
screen=SDL_SetVideoMode(600,600,32,SDL_SWSURFACE|SDL_DOUBLEBUF);

if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}



int xpos, ypos = 0;

ShowBMP("data/logo.bmp", screen, 0, 0);
//ShowBMP("data/meatball.bmp", screen, 0, 0);

blit_mb(0, 0);

int done=0;
while(done == 0)
{
SDL_Event event;

while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
done = 1;

if(event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
done = 1;
}

Uint8* keys;
keys = SDL_GetKeyState(NULL);

if(keys[SDLK_UP])
ypos -= 5;
if(keys[SDLK_DOWN])
ypos += 5;
if(keys[SDLK_LEFT])
xpos -= 5;
if(keys[SDLK_RIGHT])
xpos += 5;
//ShowBMP("data/meatball.bmp", screen, xpos, ypos);
blit_mb(xpos, ypos);
SDL_UpdateRect(screen, 25, 25, xpos-25, ypos-25);

//SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB(image->format,
255, 255, 255));

//patchbg(xpos, ypos);

//ShowBMP("data/meatball.bmp", screen, x, y);
//ShowBMP("data/logo.bmp", screen, 0, 0);
//ShowBMP("data/meatball.bmp", screen, x, y);
//SDL_Flip(screen);
}

}
return 0;
}
 
O

Old Wolf

Alvin said:
Right. I`m using Dev-Cpp, and I`m working on a game at this time in SDL
(http://libsdl.org), and I`ve come across this error:

------------------------------------------
main.c: In function `SDL_main':
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program
main.c:140: error: stray '\160' in program

That '140' means that the error is on line 140 of your program.
Please paste lines 139-141 and not the rest, we can't tell from
your listing which line is line 140.

If you don't see anything obviously wrong with those lines, try
deleting them and re-typing them, you might have gotten a
stray control character in there somewhere.

in ASCII, '\160' is the lower case letter 'o', so it is a bit of a
strange compiler message.

Another likely possibilitiy is that you've saved the source file
as UTF-8, and the compiler is expecting iso-8859-1 (or
some other non-unicode encoding). Try hex-dumping the
source file at about line 140, and check that it isn't in UTF-8.
 
R

Robert Gamble

Old said:
That '140' means that the error is on line 140 of your program.
Please paste lines 139-141 and not the rest, we can't tell from
your listing which line is line 140.

If you don't see anything obviously wrong with those lines, try
deleting them and re-typing them, you might have gotten a
stray control character in there somewhere.

in ASCII, '\160' is the lower case letter 'o', so it is a bit of a
strange compiler message.

<pedantic_nitpick>
'\160' is the lower case letter 'p' in ASCII.
</pedantic_nitpick>

Robert Gamble
 
R

Richard Heathfield

Alvin said:
Right. I`m using Dev-Cpp, and I`m working on a game at this time in SDL
(http://libsdl.org), and I`ve come across this error:

The code you posted does not include an SDL_main function. It is possible
that it has (unwisely) been defined in a header which you forgot to show us
- "include/SDL_std.h" - but it is not possible for us to help you much
further if you don't show us the relevant file.

The most likely explanation, though, is that you've accidentally included a
control character in your source file. I suggest re-typing the line from
scratch (DON'T copy/paste it!), deleting the original line, and then
re-trying the compilation.
 
R

Richard Tobin

Alvin said:
main.c:140: error: stray '\160' in program

160 (hex) in Unicode and various Latin-* encodings is non-breaking space.
You've probably managed to get one of these instead of a normal space
character in your program.

-- Richard
 
S

Skarmander

Robert said:
<pedantic_nitpick>
'\160' is the lower case letter 'p' in ASCII.
</pedantic_nitpick>
It is common for applications (even C compilers) to output escaped
characters (not occurring in the source as constants) as decimal, not octal.

\160, if interpreted this way, is outside the range of ASCII. In many
extensions of ASCII (and Unicode), this character represents a
non-breaking space. It's common to produce this character with
shift+space, so it's easy enough to accidentally type, and obviously it
looks exactly like a space in most representations.

S.
 
K

Keith Thompson

Skarmander said:
It is common for applications (even C compilers) to output escaped
characters (not occurring in the source as constants) as decimal, not
octal.

\160, if interpreted this way, is outside the range of ASCII. In many
extensions of ASCII (and Unicode), this character represents a
non-breaking space. It's common to produce this character with
shift+space, so it's easy enough to accidentally type, and obviously
it looks exactly like a space in most representations.

If so, that's a *very* peculiar error message. If a compiler found a
stray character 160-decimal in a source file, I wouldn't be surprised
to see an error message referring to 160, but I'd be astonished to see
a C compiler use a syntax, '\160', that *unambiguously* refers to the
character 160-octal (lower case 'p', assuming ASCII).

[... I go off and try some tests. ...]

Ok, hang on a second. I'm guessing that Dev-Cpp is based on gcc. I
just tried compiling a program that had a stray character 160-decimal
in it, using gcc 4.0.2. The error message was:

tmp.c:2: error: stray '\160' in program

So it *is* actually using C's syntax for an octal character constant,
but referring to the decimal value.

My prediction that I would be astonished if I saw this turns out to
have been accurate.

You have a stray non-printable character in the file "main.c". As
Skarmander says, character 160-decimal is typically something like a
non-breaking space; it may not appear odd in your text editor. If
you're on a Unix-like system, try something like

sed -n 140p main.c | od -c

If not, use some other method to look at the actual contents of the
line. This should show a character 240 (octal) on that line (or 0xa0
in hexadecimal).

Edit your main.c file, and delete and re-enter line 140.
 
A

Alvin

Thanks for all your help. I`ll try and ocmpile this when I get home
later. I`ve know Dev-Cpp to emmit odd characters when holding space
before, so I wouldnt be suprised if it was a non-breaking space.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top