Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C++ character comparison


  • Please log in to reply
5 replies to this topic

#1 sausage

sausage

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:12:29 PM

Posted 09 April 2009 - 10:19 PM

So, in my ASCII ROG (yes, that one) I am trying to compare the wall (#219 on the ASCII chart) to 219 (pretty much just check if I am moving into it.)

This segment, for some reason does not check character value but array position... I am almost positive that there is a special way to compare character values (in java is string.equals()) But I am not sure what it is or what to look up to find it

if(map[index[0]][index[1]-1] != 219) // index[0] is the X coordinate and index[1] is the Y coordinate, this is the check when moving down

I would appreciate the library the function is located in :thumbsup:

Edited by sausage, 09 April 2009 - 10:20 PM.


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:29 AM

Posted 09 April 2009 - 11:53 PM

What is map[] defined as?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:12:29 PM

Posted 10 April 2009 - 07:26 AM

char why?

EDIT: or to be more specific
char map[30][30];

Edited by sausage, 10 April 2009 - 07:31 AM.


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:29 AM

Posted 10 April 2009 - 10:50 AM

No.. I mean what does the map variable contain when you're trying to work with it?

What is your expected behavior?
What are you actually getting?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:12:29 PM

Posted 10 April 2009 - 04:38 PM

it contains a bunch of dots (walkable space) and some walls (ASCII character #219)
defined as
for(int i = 0; i < 30; ++i)
	{
			map[0][i] = 219;
			map[29][i] = 219;
			map[i][0] = 219;
			map[i][29] = 219;
	}
	
	for(int i = 1; i < 29; ++i)
	{
			for(int j = 1; j < 29; ++j)
			{
					map[j][i] = '.';
			}
	}

the expected behavior is that you can move along the dots and not move into the walls

I am getting the ability to walk through the dots and through the walls.

EDIT: Error fixed, for some reason it was declaring the wall as a -37 value??? not sure why it is but I fixed it and now I don't walk through walls hooray!

Edited by sausage, 10 April 2009 - 05:05 PM.


#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:29 AM

Posted 10 April 2009 - 08:47 PM

You need to declare it as an unsigned char. Max value for a signed char is ~128.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users