Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with code (parse error)

BWIGLEY
Guest
 
Posts: n/a
#1: Sep 30 '06
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error before "top_x"
28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
35 C:\c\Rooms\Untitled1.c parse error before '}' token

Why are these happening?

int room_square[25][20], selected = 1, squares = 1, first_square_x
= -1, first_square_y = 1;


void scr_make_room(void) //Make a room
{
int top_x, roomx, top_y, roomy, xplus, yplus;

top_x = 8; //floor(random(21))+1 //Do this later when
roomx = 5; //floor(random(8))+1 //I can use random()
top_y = 12; //floor(random(16))+1 // and floor()
roomy = 5; //floor(random(8))+1

//Turn all the wall squares within the room to floor
for (xplus = 0; xplus < roomx; xplus++)
{
for (yplus = 0; yplus < roomy; xplus++)
{

// make sure it's in the room
20: if top_x + xplus < 24 && top_y + yplus < 19 //***PARSE
ERROR
{
if room_square[top_x+xplus][top_y+yplus] == 0 //if
there is wall
{
room_square[top_x+xplus][top_y+yplus] = 1; //make
it floor
squares+=1; //increase the number of squares made

//record the first square made(ever)
28: if first_square_x == -1 //***PARSE ERROR
{
first_square_x = top_x+xplus;
first_square_y = top_y+yplus;
}//endi
}//endi wall
}//endi in room
35: }//end for y //***PARSE ERROR
}//end for x
}//end scr_make_room()

int main()
{
int i, j;

for (i = 0; i < 25; i++)
{
for (j = 0; j < 20; i++)
{
room_square[i][j]=0;
}
}

for (i=0; i<5; i+=1) //make 5 rooms
{
scr_make_room();
}

return 0;
}




Eric Sosman
Guest
 
Posts: n/a
#2: Sep 30 '06

re: Help with code (parse error)


BWIGLEY wrote:
Quote:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error before "top_x"
28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
35 C:\c\Rooms\Untitled1.c parse error before '}' token
>
Why are these happening?
Because you have omitted the parentheses in the if(...)
construct. They are not optional.

if (x < y) /* pass "Go," collect $200 */

if x < y /* go to jail. go directly to jail. */

--
Eric Sosman
esosman@acm-dot-org.invalid
Robert Gamble
Guest
 
Posts: n/a
#3: Sep 30 '06

re: Help with code (parse error)


BWIGLEY wrote:
Quote:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error before "top_x"
28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
35 C:\c\Rooms\Untitled1.c parse error before '}' token
>
Why are these happening?
>
int room_square[25][20], selected = 1, squares = 1, first_square_x
= -1, first_square_y = 1;
>
>
void scr_make_room(void) //Make a room
{
int top_x, roomx, top_y, roomy, xplus, yplus;
>
top_x = 8; //floor(random(21))+1 //Do this later when
roomx = 5; //floor(random(8))+1 //I can use random()
top_y = 12; //floor(random(16))+1 // and floor()
roomy = 5; //floor(random(8))+1
>
//Turn all the wall squares within the room to floor
for (xplus = 0; xplus < roomx; xplus++)
{
for (yplus = 0; yplus < roomy; xplus++)
{
>
// make sure it's in the room
20: if top_x + xplus < 24 && top_y + yplus < 19 //***PARSE
ERROR
if (top_x + xplus < 24 && top_y + yplus < 19) /* You need the
parenthesis */

Robert Gamble

BWIGLEY
Guest
 
Posts: n/a
#4: Sep 30 '06

re: Help with code (parse error)


"Eric Sosman" <esosman@acm-dot-org.invalidwrote in message
news:MeCdnX1oAvGoS4DYnZ2dnUVZ_oKdnZ2d@comcast.com. ..
Quote:
BWIGLEY wrote:
Quote:
Basically I've just started making a game. So far it makes an
array
Quote:
Quote:
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error before "top_x"
28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
35 C:\c\Rooms\Untitled1.c parse error before '}' token

Why are these happening?
>
Because you have omitted the parentheses in the if(...)
construct. They are not optional.
>
if (x < y) /* pass "Go," collect $200 */
>
if x < y /* go to jail. go directly to jail. */
Thanks. Anyone know why it crashes when I try to run it?


BWIGLEY
Guest
 
Posts: n/a
#5: Sep 30 '06

re: Help with code (parse error)


"BWIGLEY" <bwigley@ihug.co.nzwrote in message
news:efkme5$sa1$1@lust.ihug.co.nz...
Quote:
"Eric Sosman" <esosman@acm-dot-org.invalidwrote in message
news:MeCdnX1oAvGoS4DYnZ2dnUVZ_oKdnZ2d@comcast.com. ..
Quote:
BWIGLEY wrote:
Quote:
Basically I've just started making a game. So far it makes an
array
Quote:
Quote:
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error before "top_x"
28 C:\c\Rooms\Untitled1.c parse error before "first_square_x"
35 C:\c\Rooms\Untitled1.c parse error before '}' token
>
Why are these happening?
Because you have omitted the parentheses in the if(...)
construct. They are not optional.

if (x < y) /* pass "Go," collect $200 */

if x < y /* go to jail. go directly to jail. */
>
Thanks. Anyone know why it crashes when I try to run it?
OK, it's crashing because it's trying to put "0" in lots of memory in:

for (i = 0; i < 25; i++)
{
for (j = 0; j < 20; i++)
{
room_square[i][j]=0;
}
}

i just keeps going up. What's wrong with it.


jmcgill
Guest
 
Posts: n/a
#6: Sep 30 '06

re: Help with code (parse error)


BWIGLEY wrote:
Quote:
Thanks. Anyone know why it crashes when I try to run it?
You are incrementing i when you mean to increment j.
BWIGLEY
Guest
 
Posts: n/a
#7: Sep 30 '06

re: Help with code (parse error)



"jmcgill" <jmcgill@email.arizona.eduwrote in message
news:gklTg.500$rS.250@fed1read05...
Quote:
BWIGLEY wrote:
>
Quote:
Thanks. Anyone know why it crashes when I try to run it?
>
You are incrementing i when you mean to increment j.
Oops. Thanks


jmcgill
Guest
 
Posts: n/a
#8: Sep 30 '06

re: Help with code (parse error)


BWIGLEY wrote:
Quote:
Thanks. Anyone know why it crashes when I try to run it?
Fixed as far as I could understand it, attached.

BWIGLEY
Guest
 
Posts: n/a
#9: Sep 30 '06

re: Help with code (parse error)


"jmcgill" <jmcgill@email.arizona.eduwrote in message
news:OolTg.501$rS.229@fed1read05...
Quote:
BWIGLEY wrote:
Quote:
Thanks. Anyone know why it crashes when I try to run it?
>
Fixed as far as I could understand it, attached.
>
<snip re-formatted code>

Thanks, this is very much appreciated. From now on I think I'll
format my code like this.

I don't know if anyone can be bothered, but if someone could please
tell me how to use random() and floor() ( what to #include etc.) so I
can actually randomly generate a level (I've finished everything else
and it works nicely). I'll probably be able to find this, but they
aren't in the tutorials I've downloaded so far...


jmcgill
Guest
 
Posts: n/a
#10: Sep 30 '06

re: Help with code (parse error)


BWIGLEY wrote:
Quote:
Quote:
Quote:
>>Thanks. Anyone know why it crashes when I try to run it?
>Fixed as far as I could understand it, attached.
>>
<snip re-formatted code>
>
Thanks, this is very much appreciated. From now on I think I'll
format my code like this.
>
I don't know if anyone can be bothered, but if someone could please
tell me how to use random()
random() is not standard C.

In standard C you get RAND_MAX which is at least 32767 (but probably is
the maximum int for your system), you get rand() which gives a random
int between [0 and RAND_MAX] inclusive, and a seed function,
void srand(unsigned int seed);

To get a double precision random number, you can do this, no guarantees
about the distribution or anything.

double r;
r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );

(Personally, I've been using the random number generator from a crypto
library, not the standard function).
Quote:
and floor()
floor() is in <math.h>
BWIGLEY
Guest
 
Posts: n/a
#11: Sep 30 '06

re: Help with code (parse error)


"jmcgill" <jmcgill@email.arizona.eduwrote in message
news:rAnTg.509$rS.150@fed1read05...
Quote:
BWIGLEY wrote:
Quote:
Quote:
>Thanks. Anyone know why it crashes when I try to run it?
Fixed as far as I could understand it, attached.
>
<snip re-formatted code>

Thanks, this is very much appreciated. From now on I think I'll
format my code like this.

I don't know if anyone can be bothered, but if someone could
please
Quote:
Quote:
tell me how to use random()
>
random() is not standard C.
>
In standard C you get RAND_MAX which is at least 32767 (but probably
is
Quote:
the maximum int for your system), you get rand() which gives a
random
Quote:
int between [0 and RAND_MAX] inclusive, and a seed function,
void srand(unsigned int seed);
>
To get a double precision random number, you can do this, no
guarantees
Quote:
about the distribution or anything.
>
double r;
r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );
>
(Personally, I've been using the random number generator from a
crypto
Quote:
library, not the standard function).
>
Quote:
and floor()
>
floor() is in <math.h>
Thanks, I've got it working perfectly now. How should I print the
array to the screen?


BWIGLEY
Guest
 
Posts: n/a
#12: Sep 30 '06

re: Help with code (parse error)


"BWIGLEY" <bwigley@ihug.co.nzwrote in message
news:eflam2$1mo$1@lust.ihug.co.nz...
Quote:
"jmcgill" <jmcgill@email.arizona.eduwrote in message
news:rAnTg.509$rS.150@fed1read05...
Quote:
BWIGLEY wrote:
<snip>
Quote:
Thanks, I've got it working perfectly now. How should I print the
array to the screen?
BTW, here's the source so far:

/*Program outline
Make 5 rooms, randomly placed
Try to select all squares that touch the first square (and select ones
near them etc.)
If all not all squares are selected make 2 more rooms
retry selecting (only ones that don't have selected squares all around
them)
repeat room creation, selection trying etc.
If at any time it's close to having all squares selected delete all
unselected squares
Convert selected squares to floor (1)
*/

#include <stdio.h//input + output
#include <math.h//for floor
#include <stdlib.h//Random #'s
#include <time.h//Random #'s

int room_square[25][25],
selected = 0,
squares = 0,
first_square_x = -1,
first_square_y = 0;

//Make a room
void scr_make_room(void) {

int top_x, roomx, top_y, roomy, xplus, yplus;
//printf("%f\n",(rand()/(RAND_MAX + 1)) * 21);
top_x = rand() / (RAND_MAX / 21 + 1) +1; //floor(random(21))+1
roomx = rand() / (RAND_MAX / 8 + 1) +1; //floor(random(8))+1
top_y = rand() / (RAND_MAX / 21 + 1) +1; //floor(random(16))+1
roomy = rand() / (RAND_MAX / 8 + 1) +1; //floor(random(8))+1

//Turn all the wall squares within the room to floor
for (xplus = 0; xplus < roomx; xplus++) {
for (yplus = 0; yplus < roomy; yplus++) {

// make sure it's in the room
if (top_x + xplus < 24 && top_y + yplus < 24) {
if (room_square[top_x + xplus][top_y + yplus] == 0) {
room_square[top_x + xplus][top_y + yplus] = 1;
//make it floor
squares++; //increase the number of squares made

//record the first square made(ever)
if (first_square_x == -1) {
first_square_x = top_x + xplus;
first_square_y = top_y + yplus;
} //endi first square
} //endi wall
} //endi in room
} //end for y
} //end for x
} //end scr_make_room()

void scr_select_squares(int square_x, int square_y) {

int amnt = 0;
if ((room_square[square_x-1][square_y] == -1 ||
room_square[square_x-1][square_y] == -2) && //if all 'round it's
selected be done
(room_square[square_x+1][square_y] == -1 ||
room_square[square_x+1][square_y] == -2) &&
(room_square[square_x][square_y-1] == -1 ||
room_square[square_x][square_y-1] == -2) &&
(room_square[square_x][square_y+1] == -1 ||
room_square[square_x][square_y+1] == -2)) {
room_square[square_x][square_y] = -2;
}
else { //if they're not all selected, try to do it
//select to the left
if (square_x-1 0) { //in the room
if (room_square[square_x-1][square_y] == 1) { //if it's
floor
room_square[square_x-1][square_y] = -1; //Select it
selected++; //increase no. selected
scr_select_squares(square_x-1, square_y); //select
squares around it
}
}

//right
if (square_x+1 < 24) { //in the room
if (room_square[square_x+1][square_y] == 1) { //if it's
floor
room_square[square_x+1][square_y] = -1; //Select it
selected++; //increase no. selected
scr_select_squares(square_x+1, square_y); //select
squares around it
}
}

//Up
if (square_y - 1 0) { //in the room
if (room_square[square_x][square_y-1] == 1) { //if it's
floor
room_square[square_x][square_y-1] = -1; //Select it
selected++; //increase no. selected
scr_select_squares(square_x, square_y-1); //select
squares around it
}
}

//Down
if (square_y + 1 < 24) { //in the room
if (room_square[square_x][square_y+1] == 1) { //if it's
floor
room_square[square_x][square_y+1] = -1; //Select it
selected++; //increase no. selected
scr_select_squares(square_x, square_y+1); //select
squares around it
}
}
}
}

int main(int argc, char** argv) {

int i, j;

srand((unsigned)time(NULL)); //Init rng

for (i = 0; i < 25; i++) {
for (j = 0; j < 25; j++) {
room_square[i][j] = 0;
}
}

for (i = 0; i < 5; i++) {
scr_make_room();
}

//select the first square
room_square[first_square_x][first_square_y] = -1;
selected++;
//select all squares around it
scr_select_squares(first_square_x, first_square_y);

//***ROOM GENERATION LOOP!!!
while (selected != squares) {

//select squares
for (i=1; i<24; i++) {
for (j=1; j<24; j++) {
if (room_square[i][j] == -1) {
scr_select_squares(i,j);
}
}
}

//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
switch (room_square[i][j]){
case 0:{
printf("0");
};break;
case 1:{
printf(".");
};break;
case -1:{
printf("s");
};break;
case -2:{
printf("-");
};break;

}
//printf("%d", room_square[i][j]);
}
}
printf("\n");
getch();



//if most squares are selected delete the unselected ones
if (squares < selected+5 && selected!=squares) {
for (i=1; i<24; i++) {
for (j=1; j<24; j++) {
if (room_square[i][j] == 1) {
room_square[i][j] = 0;
squares--;
}
}
}
}

//make some rooms if theres squares still unselected squares
if (selected != squares) {
scr_make_room();
scr_make_room();
}
}//end while
//***Now we have one contigous space of floor!

//make selected spaces floor
for (i=1; i<24; i++) {
for (j=1; j<24; j++) {
if (room_square[i][j] == -1 || room_square[i][j] == -2) {
room_square[i][j] = 1;
}
}
}

//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
switch (room_square[i][j]){
case 0:{
printf("0");
};break;
case 1:{
printf(".");
};break;
}
//printf("%d", room_square[i][j]);
}
}
printf("\nsquares: %d", squares);
printf("\nselected: %d", selected);

getch(); //just so it doesn't exit on windoze
return 0;
}


Snis Pilbor
Guest
 
Posts: n/a
#13: Sep 30 '06

re: Help with code (parse error)



BWIGLEY wrote:
Quote:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
By the way, since you seem to be making a 2d look-down-on-the-action
game, you might be interested in the much more topical
rec.games.roguelike.development. That group is devoted to programming
this sort of game, and in particular the amount of literature on
generating 2d maps in an array is staggering.

Barry Schwarz
Guest
 
Posts: n/a
#14: Sep 30 '06

re: Help with code (parse error)


On Fri, 29 Sep 2006 22:52:16 -0700, jmcgill
<jmcgill@email.arizona.eduwrote:
Quote:
>BWIGLEY wrote:
Quote:
Quote:
>>>Thanks. Anyone know why it crashes when I try to run it?
>>Fixed as far as I could understand it, attached.
>>>
><snip re-formatted code>
>>
>Thanks, this is very much appreciated. From now on I think I'll
>format my code like this.
>>
>I don't know if anyone can be bothered, but if someone could please
>tell me how to use random()
>
>random() is not standard C.
>
>In standard C you get RAND_MAX which is at least 32767 (but probably is
>the maximum int for your system), you get rand() which gives a random
>int between [0 and RAND_MAX] inclusive, and a seed function,
>void srand(unsigned int seed);
>
>To get a double precision random number, you can do this, no guarantees
>about the distribution or anything.
>
>double r;
>r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );
You don't need any of the casts. 1.0 is already a double. The +
operator will force RAND_MAX to be converted to double. That will
make the denominator a double. The / operator will force the
numerator to be converted to double. That will make the quotient a
double.

Why did you add +1? Your code will give a value in the range [0,1).
It can produce 0 but can never produce 1. Was there something in the
OP's concept that would make 1 undesirable?
Quote:
>
>(Personally, I've been using the random number generator from a crypto
>library, not the standard function).
>
Quote:
>and floor()
>
>floor() is in <math.h>

Remove del for email
Barry Schwarz
Guest
 
Posts: n/a
#15: Sep 30 '06

re: Help with code (parse error)


On Sat, 30 Sep 2006 23:25:30 +1200, "BWIGLEY" <bwigley@ihug.co.nz>
wrote:
Quote:
>"BWIGLEY" <bwigley@ihug.co.nzwrote in message
>news:eflam2$1mo$1@lust.ihug.co.nz...
Quote:
>"jmcgill" <jmcgill@email.arizona.eduwrote in message
>news:rAnTg.509$rS.150@fed1read05...
Quote:
BWIGLEY wrote:
><snip>
Quote:
>Thanks, I've got it working perfectly now. How should I print the
>array to the screen?
>
>BTW, here's the source so far:
>
>/*Program outline
>Make 5 rooms, randomly placed
>Try to select all squares that touch the first square (and select ones
>near them etc.)
>If all not all squares are selected make 2 more rooms
>retry selecting (only ones that don't have selected squares all around
>them)
>repeat room creation, selection trying etc.
>If at any time it's close to having all squares selected delete all
>unselected squares
>Convert selected squares to floor (1)
>*/
>
>#include <stdio.h//input + output
>#include <math.h//for floor
>#include <stdlib.h//Random #'s
>#include <time.h//Random #'s
>
>int room_square[25][25],
selected = 0,
squares = 0,
first_square_x = -1,
first_square_y = 0;
>
>//Make a room
>void scr_make_room(void) {
>
int top_x, roomx, top_y, roomy, xplus, yplus;
//printf("%f\n",(rand()/(RAND_MAX + 1)) * 21);
If you uncomment this, it will invoke undefined behavior. The second
argument is an int, whose value will always be zero, and the %f says
printf can expect a double.

snip rest of function
Quote:
>} //end scr_make_room()
>
>void scr_select_squares(int square_x, int square_y) {
>
int amnt = 0;
if ((room_square[square_x-1][square_y] == -1 ||
>room_square[square_x-1][square_y] == -2) && //if all 'round it's
>selected be done
You should not use // comments for usenet. They don't survive line
wraps and prevent others from compiling your code to help.

snip rest of function
Quote:
>}
>
>int main(int argc, char** argv) {
snip
Quote:
//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
switch (room_square[i][j]){
case 0:{
printf("0");
};break;
The braces, {}, are superfluous. The semicolon just after the right
brace is a null statement. Did you really mean that? If so, why? If
you are going to use braces, you should move the break statement
inside.
Quote:
case 1:{
printf(".");
};break;
case -1:{
printf("s");
};break;
case -2:{
printf("-");
};break;
>
}
//printf("%d", room_square[i][j]);
}
}
printf("\n");
getch();
This is a non-standard function. How does the user know that he
should press a key?

snip more code
Quote:
//make selected spaces floor
for (i=1; i<24; i++) {
for (j=1; j<24; j++) {
if (room_square[i][j] == -1 || room_square[i][j] == -2) {
room_square[i][j] = 1;
}
}
}
>
//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
Variety may be the spice of life but a consistent code style is a
virtue. Think about coming back to this program after several months.

snip rest of function
Quote:
>}
>

Remove del for email
Eric Sosman
Guest
 
Posts: n/a
#16: Sep 30 '06

re: Help with code (parse error)


Barry Schwarz wrote:
Quote:
On Fri, 29 Sep 2006 22:52:16 -0700, jmcgill
<jmcgill@email.arizona.eduwrote:
>
Quote:
>>
>>To get a double precision random number, you can do this, no guarantees
>>about the distribution or anything.
>>
>>double r;
>>r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );
>
>
You don't need any of the casts.
Debatable, considering "no guarantees." The code as it
stands sets r to a value somewhere between 1.0 and 2.0, with
both extremes included. Remove the casts and it will set r
to 1.0 most of the time and 2.0 rarely, never anything in
between.
Quote:
1.0 is already a double.
Right.
Quote:
The +
operator will force RAND_MAX to be converted to double.
Wrong: division "binds more tightly" than addition.
Quote:
That will
make the denominator a double. The / operator will force the
numerator to be converted to double. That will make the quotient a
double.
>
Why did you add +1? Your code will give a value in the range [0,1).
No: the range is 1.0 <= r <= 2.0. It seems likely that
this was not jmcgill's intention, but that he garbled the
usual formula

r = rand() / (RAND_MAX + 1.0);

.... for a [0,1) uniform value. (Speculation: In his attempt
to make it look fancier by adding unnecessary casts and way too
many parentheses, he lost track of which parens went with which.
If so, jmcgill should probably avoid Lisp!)

But since he said "no guarantees" we'd be in a false position
trying to tut-tut him. His code produces a pseudo-random value,
and although the probability distribution it simulates is a bit
peculiar it can't be called "wrong" without a specification.

--
Eric Sosman
esosman@acm-dot-org.invalid
jmcgill
Guest
 
Posts: n/a
#17: Sep 30 '06

re: Help with code (parse error)


Eric Sosman wrote:
Quote:
No: the range is 1.0 <= r <= 2.0. It seems likely that
this was not jmcgill's intention, but that he garbled the
usual formula
>
r = rand() / (RAND_MAX + 1.0);
>
... for a [0,1) uniform value. (Speculation: In his attempt
to make it look fancier by adding unnecessary casts and way too
many parentheses, he lost track of which parens went with which.
If so, jmcgill should probably avoid Lisp!)
Help the OP with the questions, don't tear apart my attempt to help.
Richard Heathfield
Guest
 
Posts: n/a
#18: Oct 1 '06

re: Help with code (parse error)


jmcgill said:
Quote:
Eric Sosman wrote:
>
Quote:
> No: the range is 1.0 <= r <= 2.0. It seems likely that
>this was not jmcgill's intention, but that he garbled the
>usual formula
>>
> r = rand() / (RAND_MAX + 1.0);
>>
>... for a [0,1) uniform value. (Speculation: In his attempt
>to make it look fancier by adding unnecessary casts and way too
>many parentheses, he lost track of which parens went with which.
>If so, jmcgill should probably avoid Lisp!)
>
Help the OP with the questions, don't tear apart my attempt to help.
Why not? Don't *you* want to learn something new? Most of my misconceptions
about C were only sorted out when I tried to help others, here in clc, and
my attempts to help got ripped apart by the regulars. Yes, I suppose I
could have moaned about it, but to what end? I'm *glad* I was corrected,
because it meant I was learning more about the language.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
BWIGLEY
Guest
 
Posts: n/a
#19: Oct 1 '06

re: Help with code (parse error)


"Barry Schwarz" <schwarzb@doezl.netwrote in message
news:342th2p00p23op6fdf5e22bjvsjsqtb272@4ax.com...
Quote:
On Sat, 30 Sep 2006 23:25:30 +1200, "BWIGLEY" <bwigley@ihug.co.nz>
wrote:
>
Quote:
"BWIGLEY" <bwigley@ihug.co.nzwrote in message
news:eflam2$1mo$1@lust.ihug.co.nz...
Quote:
"jmcgill" <jmcgill@email.arizona.eduwrote in message
news:rAnTg.509$rS.150@fed1read05...
BWIGLEY wrote:
<snip>
Quote:
Thanks, I've got it working perfectly now. How should I print
the
Quote:
Quote:
Quote:
array to the screen?
BTW, here's the source so far:
<snip>
Quote:
Quote:
//printf("%f\n",(rand()/(RAND_MAX + 1)) * 21);
>
If you uncomment this, it will invoke undefined behavior. The
second
Quote:
argument is an int, whose value will always be zero, and the %f says
printf can expect a double.
Yeah, I was trying to figure it out, and this was one of the ways I
tried.
Quote:
>
snip rest of function
>
Quote:
} //end scr_make_room()

void scr_select_squares(int square_x, int square_y) {

int amnt = 0;
if ((room_square[square_x-1][square_y] == -1 ||
room_square[square_x-1][square_y] == -2) && //if all 'round it's
selected be done
>
You should not use // comments for usenet. They don't survive line
wraps and prevent others from compiling your code to help.
>
Yeah, I sort of realized that after I posted this. I'll do this from
now on.
Quote:
snip rest of function
>
Quote:
}

int main(int argc, char** argv) {
>
snip
>
Quote:
//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
switch (room_square[i][j]){
case 0:{
printf("0");
};break;
>
The braces, {}, are superfluous. The semicolon just after the right
brace is a null statement. Did you really mean that? If so, why?
If
Quote:
you are going to use braces, you should move the break statement
inside.
I didn't mean that, I'll but the break statement inside my brackets
from now on.
Quote:
Quote:
}
printf("\n");
getch();
>
This is a non-standard function. How does the user know that he
should press a key?
I was just doing this to see how well the room generation worked, so
this won't be in the actual game.
Quote:
>
snip more code
>
Quote:

//lets try printing it:
for (i=0; i<25; i++) {
printf("\n");
for (j=0; j<25; j+=1) {
>
Variety may be the spice of life but a consistent code style is a
virtue. Think about coming back to this program after several
months.

Oops, I just lapsed into +=1 for a moment there.

Anyway I still don't know how to move the cursor to print text to the
screen at places, so if anyone can help me with this... I'll check
out Rec.games.roguelike.development too, I didn't realize there was
such a group so hopefully they'll have good information there.


Kenny McCormack
Guest
 
Posts: n/a
#20: Oct 1 '06

re: Help with code (parse error)


In article <s9yTg.534$rS.367@fed1read05>,
jmcgill <jmcgill@email.arizona.eduwrote:
Quote:
>Eric Sosman wrote:
>
Quote:
> No: the range is 1.0 <= r <= 2.0. It seems likely that
>this was not jmcgill's intention, but that he garbled the
>usual formula
>>
> r = rand() / (RAND_MAX + 1.0);
>>
>... for a [0,1) uniform value. (Speculation: In his attempt
>to make it look fancier by adding unnecessary casts and way too
>many parentheses, he lost track of which parens went with which.
>If so, jmcgill should probably avoid Lisp!)
>
>Help the OP with the questions, don't tear apart my attempt to help.
You're new here, aren't you?

Barry Schwarz
Guest
 
Posts: n/a
#21: Oct 1 '06

re: Help with code (parse error)


On Sat, 30 Sep 2006 13:18:26 -0400, Eric Sosman
<esosman@acm-dot-org.invalidwrote:
Quote:
>Barry Schwarz wrote:
Quote:
>On Fri, 29 Sep 2006 22:52:16 -0700, jmcgill
><jmcgill@email.arizona.eduwrote:
>>
Quote:
>>>
>>>To get a double precision random number, you can do this, no guarantees
>>>about the distribution or anything.
>>>
>>>double r;
>>>r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );
>>
>>
>You don't need any of the casts.
>
Debatable, considering "no guarantees." The code as it
>stands sets r to a value somewhere between 1.0 and 2.0, with
>both extremes included. Remove the casts and it will set r
>to 1.0 most of the time and 2.0 rarely, never anything in
>between.
>
Quote:
>1.0 is already a double.
>
Right.
>
Quote:
>The +
>operator will force RAND_MAX to be converted to double.
>
Wrong: division "binds more tightly" than addition.
All too true. I must remember to where my glasses when the
parentheses nesting level exceeds 1.


Remove del for email
Barry Schwarz
Guest
 
Posts: n/a
#22: Oct 1 '06

re: Help with code (parse error)


On Sun, 1 Oct 2006 21:42:15 +1300, "BWIGLEY" <bwigley@ihug.co.nz>
wrote:


snip
Quote:
>Anyway I still don't know how to move the cursor to print text to the
>screen at places, so if anyone can help me with this... I'll check
>out Rec.games.roguelike.development too, I didn't realize there was
>such a group so hopefully they'll have good information there.
>
Unfortunately, that is system specific. You will need to ask in a
forum that discusses your system (hardware, OS, and run-time library).


Remove del for email
Closed Thread