Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Ignore White Space?

Author
Message
DragonsLair
15
Years of Service
User Offline
Joined: 3rd May 2009
Location: Scarborough
Posted: 2nd Jun 2009 13:35
Im importing a string from a text file which read\'s \'test\';

loaded as such:


but when I do this:



It does not display that they are a match.

If i remove the \'if\' commends leaving:

dbPrint(\"TEST SUCCESS\");

It displays the text fine.

Do I need to remove the whitespace somehow? None of the code I have found works for it though.

Any thought?

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 2nd Jun 2009 14:24 Edited at: 2nd Jun 2009 14:25
It looks like you don't understand C strings and pointers. You should have a detailed read of the below links from www.cplusplus.com. Once you understand everything in these tutorials you should see what you are doing wrong. Your code compares the memory address of the character array 'datafile' with "test". You should be comparing the contents of 'datafile' with "test". You need to compare each character individually and can do this using strcmp.

Links:
Arrays
Pointers
Character Sequences

DragonsLair
15
Years of Service
User Offline
Joined: 3rd May 2009
Location: Scarborough
Posted: 2nd Jun 2009 14:28
ah ok. no i dont quite understand. Im used to c#, asp and php mainly.

Thanks for that as well thats excellent cheers

DragonsLair
15
Years of Service
User Offline
Joined: 3rd May 2009
Location: Scarborough
Posted: 2nd Jun 2009 15:14
mind bogling lol

Trying to read through em and I dont quite get it?

I know its a lot to ask but does anyone have a couple of lines of code as an example?

Im finding it quite hard to get.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Jun 2009 17:05
if (strcmp(datafile,"test") == 0)

Because it is a pointer to an array of chars, you could have two different pointers, which pointed to two arrays of chars which had the same values in. Comparing the pointers won't compare the chars themselves. For that, you can either do it manually, or use the built in functions such as 'strcmp' (It is the same as the .net function stringa.CompareTo(stringb) in that it returns 1 if the first is greater than the second, -1 if the first is less than the second, and 0 if they are equal.

Login to post a reply

Server time is: 2024-11-25 10:50:42
Your offset time is: 2024-11-25 10:50:42