Skip to main content
gamedev.net
🔒 Locked

STRING to INT

Started by MetaKnight Mar 18, 2003 at 4:24 PM 9 replies 550+ views
Original Post
MetaKnight
MetaKnight
Does anyone know how get the 10 from the char* CAMERA10
Cybertron
Cybertron
the C library function atoi and other string functions, look in MSDN for it

Thats that last thing you need slowing down your program is a string class wasting memory all over the place

Whatever works for you though!
Cybertron
Cybertron
No I don''t have my flying car yet! Or my robot maid or a space odessy.

I see nothing wrong with the old string functions for what I use them for. Of course if your program is based entirely on string processing I am sure a class is needed
darookie
darookie
quote:
Original post by Cybertron
Whatever works for you though!


Russell
Russell
quote:
Original post by Anonymous Poster
Cybertron, didn''t you notice it''s already the 21st century?
What does the 21st century have to do with being wasteful? Is being wasteful goin to be more accepted in the future? Don''t think so...

To the original poster, you need to know your data. For example, is it always going to be contiguous letters followed by a number? If so, you could do something like this:
  // untested code

int StripNumber (char * s) {
for (; !isdigit(*s); s++)
;
return atoi(s);
}
Russell
Russell
quote:
Original post by Anonymous Poster
For example, the function you gave will make the program crash if the string doesn''t contain any numbers.

quote:
Original post by Russell For example, is it always going to be contiguous letters followed by a number? If so, you could do something like this

Besides, it depends what you''re doing. You talk about how horrible the security issues are from buffer overflows, and if I''m writing a web server, then maybe I need to think about that, and maybe I should also think about whether I want my web server''s performance to suffer from reallocating memory and copying strings left and right. Since most of us are not writing web servers, this probably isn''t that big of a deal.
CaptainJester
CaptainJester
quote:
Original post by Russell
Besides, it depends what you''re doing. You talk about how horrible the security issues are from buffer overflows, and if I''m writing a web server, then maybe I need to think about that, and maybe I should also think about whether I want my web server''s performance to suffer from reallocating memory and copying strings left and right. Since most of us are not writing web servers, this probably isn''t that big of a deal.


True, but you should always do error checking even when writing the simplest code. This way it becomes a habit and when you work on bigger projects, you get less bug creep.



First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
MetaKnight
MetaKnight
Ah very nice, thanks guys
peacfuly brillant!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.