Home

A nice and elaborated ski game. The website seems to be unavailable but the source code is easy to find on various places. I had a little trouble making it work under my Raspberry Pi computer; see below for instructions.

asciijump

Compiling asciijump on a Raspberry Pi

After compiling the game on a Raspberry Pi, I noticed I couldn’t make it work. The package in the distribution doesn’t work either! After a little debugging, I discovered that the file xfnc.c contains a function called xgetline with a little bug. The (wrong) code is the following:

char *xgetline(FILE *fd)
{
	int length = 1;
	int i = 0;
	char *line = NULL;

	for (;;) {
		if (length-1 == i) {
			length *=3;
			line = xrealloc(line, length*(sizeof(char)));
		}
		
		line[i] = fgetc(fd);

		if (line[i] == EOF) {
			if (i == 0)
				return NULL;
			line[i] = '';
			break;

		} else if (line[i] == '\n') {
			if (i == 0)
				return xgetline(fd);
			line[i] = '';
			break;
		}
		i++;
	}
	
	return line;
}

You have to replace it with:

char *xgetline(FILE *fd)
{
	int length = 1;
	int i = 0;
	char *line = NULL;
        int c;

	for (;;) {
		if (length-1 == i) {
			length *=3;
			line = xrealloc(line, length*(sizeof(char)));
		}
		
		c = fgetc(fd);

		if (c == EOF) {
			if (i == 0)
				return NULL;
			line[i] = '';
			break;

		} else if (c == '\n') {
			if (i == 0)
				return xgetline(fd);
			line[i] = '';
			break;
		}
                line[i] = (char) c;
		i++;
	}
	
	return line;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s