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 / The dbLimbName function

Author
Message
Benjames8
14
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 28th Jan 2011 00:44 Edited at: 28th Jan 2011 00:45
So the dbLimbName function returns char* of the limb's name obviously. I can compare the name with a string using strcmp(), or return the length using strlen(), or even return the position of a spacific character using strcspn().

What I want to really do is retrieve the character in a specific slot. Like the first letter or the fifth letter.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 28th Jan 2011 01:26 Edited at: 28th Jan 2011 01:28
Have you considered using std::string?
I use it a lot and it's an easy and safe way to handle strings.

You could then do it like this:



Look here for more info.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Benjames8
14
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 28th Jan 2011 04:50 Edited at: 28th Jan 2011 06:00
You should try this yourself.. it gives a linker error

I think it is because what dbLimbName return's.

maybe I should have this Jaguar eat your brains for your bad advice
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 28th Jan 2011 05:44 Edited at: 28th Jan 2011 05:47
Use the subscript operator: []



“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Benjames8
14
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 28th Jan 2011 06:03 Edited at: 28th Jan 2011 06:14
I don't see how I am sapposed to extract from dbLimbName the characters to place in the array char str[32];

[edit] Ok I got it, sorry for being pissy btw.

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Jan 2011 06:31 Edited at: 28th Jan 2011 06:32
As _Pauli_ says, use std::string, it gives you bounds checking when using the [] operator. However, make sure you store the returned string in a char* first, then copy it into the std::string and finally delete[] the char* string, else you'll leak memory.

As for the linker errors, there's a billion threads around here about this and describing the solution.

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 28th Jan 2011 11:33 Edited at: 28th Jan 2011 11:34
Quote: "maybe I should have this Jaguar eat your brains for your bad advice"


I guess that's supposed to be a joke. A simple "Thank you" would have been enough.
Set your runtime to /MT (instead of /MTd) in your project settings or build in Release mode and you shouldn't have linker errors with <string> anymore.
Man, use it. It will solve all your string related problems forever.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.

Login to post a reply

Server time is: 2024-11-19 14:24:07
Your offset time is: 2024-11-19 14:24:07