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 / Werid if problem...

Author
Message
General Reed
18
Years of Service
User Offline
Joined: 24th Feb 2006
Location:
Posted: 27th Jan 2008 18:24
if u do this
extension = dbRight(filename, length - (currentPosition + 1));

then it wont exit

but if u do this

then it will exit

ive checked that in the first one extension is equal to a lower case x

and in both cases, they have a length of one

What am i doing wrong here?

CPU: AMD X2 6000+ 3.0ghz GFX: NVIDIA BFG Geforce 8800GTS 640MB OC-550mhz core RAM: 2048mb

Sephnroth
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 27th Jan 2008 18:28
its not really safe to compare strings that way. a much better idea would be to use strcmp() - heres how to use it:

http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html

General Reed
18
Years of Service
User Offline
Joined: 24th Feb 2006
Location:
Posted: 28th Jan 2008 14:46
Great! thanks

CPU: AMD X2 6000+ 3.0ghz GFX: NVIDIA BFG Geforce 8800GTS 640MB OC-550mhz core RAM: 2048mb

monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 28th Jan 2008 14:58
Or even safer use s_strcmp.

The Sun is trying to kill me!
General Reed
18
Years of Service
User Offline
Joined: 24th Feb 2006
Location:
Posted: 28th Jan 2008 20:14
Why is it actualy "unsafe" in the firstplace?

CPU: AMD X2 6000+ 3.0ghz GFX: NVIDIA BFG Geforce 8800GTS 640MB OC-550mhz core RAM: 2048mb

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 28th Jan 2008 20:38
buffer overflow , probably
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Jan 2008 20:50
It's not a case of it being unsafe, it's that what you're expecting it does isn't actually what it does. When you compare strings like that, you're actually comparing pointers. Consequently, this is useless unless you want to see if both pointers are the same, which you don't. You want to check if the data behind the pointers is the same. This is what you use strcmp() for.

General Reed
18
Years of Service
User Offline
Joined: 24th Feb 2006
Location:
Posted: 28th Jan 2008 21:32
Oh ok thanks!

CPU: AMD X2 6000+ 3.0ghz GFX: NVIDIA BFG Geforce 8800GTS 640MB OC-550mhz core RAM: 2048mb

monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 29th Jan 2008 14:00
Quote: "buffer overflow , probably"


Precisely, they be very dangerous indeed aaarrrghh

The Sun is trying to kill me!
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 29th Jan 2008 17:11
You may as well just use std::string for everything, makes life easier.

The Sun is trying to kill me!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Jan 2008 18:01
It is easier at first, but char* is more.. I dunno how to put it.. flexible

I use std::string for things only when I need to do things like appending the string, etc.

Your signature has been erased by a mod
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 29th Jan 2008 19:46
True, char* are more flexible but like you say when performing string related tasks the std::string is easier.

The Sun is trying to kill me!
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 30th Jan 2008 12:40 Edited at: 30th Jan 2008 12:41
Quote: "Though you can simply cast it to a string, e.g"

It's possible, but a null pointer will cause a crash. And it's not a terribly efficient thing to do either.

Login to post a reply

Server time is: 2024-09-29 11:31:05
Your offset time is: 2024-09-29 11:31:05