• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Braeden

A conversion prgram

7 posts in this topic

I've been trying to work out how to convert strings to integers, ex "Hello world" should become "7.5.12.12.15 23.15.17.12.4". How would I do this? I dont want source code, I just want a basic explanation so I can figure out exactly how to use it. Thanks guys
0

Share this post


Link to post
Share on other sites
Break the string into a series chars, C_str should do fine. Then cast every character to an unsigned int.
0

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1348724734' post='4984235']
[quote name='kd7tck' timestamp='1348715494' post='4984214']
Break the string into a series chars, C_str should do fine. Then cast every character to an unsigned int.
[/quote]
No need, as you can use [font=courier new,courier,monospace]operator[][/font] to index characters in the string.

@OP: I'd use [url="http://www.cplusplus.com/reference/algorithm/transform/"]std::transform[/url] with [url="http://www.cplusplus.com/reference/clibrary/cctype/toupper/"]std::toupper[/url] to convert the string to upper case, then I'd use [url="http://www.cplusplus.com/reference/algorithm/remove_if/"]std::remove_if[/url] to remove all the characters that weren't between 'A' and 'Z', and then all you have to do is subtract 'A' and add 1 to each character and you're good to go. Alternatively, I'd use [url="http://www.cplusplus.com/reference/algorithm/remove_if/"]std::remove_if[/url] with [url="http://www.cplusplus.com/reference/clibrary/cctype/isalpha/"]std::isalpha[/url] to get it to just alpha characters, and then use [url="http://www.cplusplus.com/reference/algorithm/transform/"]std::transform[/url] with a function that did [url="http://www.cplusplus.com/reference/clibrary/cctype/toupper/"]std::toupper()[/url] - 'A'+ 1 in one pass. Once the string is just a collection of bytes that represent the right values for each character, I'd probably just output each character to a [url="http://www.cplusplus.com/reference/iostream/ostream/"]std::ostream[/url], casting each char to an int and adding a period between numbers.

Something like that. How I'd actually do it kind of depends on the situation.
[/quote]

I didn't realize he only wanted to do uppercase letters.

Guess I should stop thinking like a C programmer.
0

Share this post


Link to post
Share on other sites
There are allot of standard functions to convert data types. stringstream, itoa, atoi, etc..
But you could also write your own conversions.. [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]

stringstream takes average 2,000,000 ms to convert int <-> string
itoa and atoi takes average 350,000 ms to convert.


[b]Offtopic[/b]
my convertions takes around 87,000ms for int to string. And around 43,000ms for string to int.

Meaning self written conversions are more effective, if good written. You are the programmer, you decide all the errorchecking.
I don't have a single check of wrong input to increase all performance. But I'm the only programmer at my projects so I know that I don't need to enter wrong input. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[b]Offtopic[/b]

~EngineProgrammer
0

Share this post


Link to post
Share on other sites
[quote name='Braeden' timestamp='1348714647' post='4984213']
I've been trying to work out how to convert strings to integers, ex "Hello world" should become "7.5.12.12.15 23.15.17.12.4". How would I do this? I dont want source code, I just want a basic explanation so I can figure out exactly how to use it. Thanks guys
[/quote]
strings are just a collection of numbers organized in a specific pattern such that each letter corrosponds to a particular number(see [url="http://en.wikipedia.org/wiki/ASCII"]ASCII[/url]), your implementation is already flawed, you use letter offset's, but you don't account between caps/lower case letters, so, assuming that capitals would come after your lowercase letters, than H would be 26+7. i'm not sure what convention you want to use, but I don't see why you can't just use the ASCII system already in place, however if you do need to change the number representing the character then Cornstalk's already provided a pretty solid implementation of what to do.

[quote name='EngineProgrammer' timestamp='1348792829' post='4984548']
There are allot of standard functions to convert data types. stringstream, itoa, atoi, etc..
But you could also write your own conversions.. [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]

stringstream takes average 2,000,000 ms to convert int <-> string
itoa and atoi takes average 350,000 ms to convert.


[b]Offtopic[/b]
my convertions takes around 87,000ms for int to string. And around 43,000ms for string to int.

Meaning self written conversions are more effective, if good written. You are the programmer, you decide all the errorchecking.
I don't have a single check of wrong input to increase all performance. But I'm the only programmer at my projects so I know that I don't need to enter wrong input. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[b]Offtopic[/b]

~EngineProgrammer
[/quote]

I truthfully hope you are either working with incredibly long strings/70's era processors, or that you simply meant micro-seconds(generally represented as 'mus' or 'us'), and not milliseconds, still, 2 seconds is a long time even for the standard library, so i'm not really sure what your doing. Edited by slicer4ever
2

Share this post


Link to post
Share on other sites
Maybe he forgot to mention something like "for 1 billion test runs". In either case it doesn't really matter, since it has little to nothing to do with the actual topic. It's not about converting string<->int, but essentially about subtracting one number from another (while skipping values outside a certain range and using a different offset depending on which range you're in).

At no point should stringstream, atoi, etc. have anything to do with it.
1

Share this post


Link to post
Share on other sites
Yeah, stringstream doesn't take 2 seconds to do a single conversion. It doesn't even take 2 millaseconds for a single conversion, so I'm not sure where that data came from, but in my own experience it's inaccurate. Yes, a hand-rolled integer conversion would be faster in most cases, so you are doing less (it's less general), but premature optimization is not good. Use hand-rolled where you need speed, otherwise don't re-invent the wheel.

[quote name='Trienco' timestamp='1348805234' post='4984589']
At no point should stringstream, atoi, etc. have anything to do with it.
[/quote]
Quoted for truth - look at Cornstalk's post. The only place int to string (not vise-versa) is needed, is for putting the results in a new string if the OP desires.

I'd do it something like this:
[i]Cast string to lowercase. (std::transform, and std::tolower)
Iterate over each char in string (just index into it)
I'd cast the char to an int
//Since ASCII lowercase letters begins at 97, and goes to 122, and space is 32...
if the int is 32[/i]
[i]. . . .[/i][i]output a '-' to the result, if desired, or leave it as a space, or discard it.
if the int is over 122 or under 97[/i]
[i]. . . .[/i][i]output a ? to the result, or discard that char
otherwise
. . . . Subtract 96, so 'a' becomes '1', and so on.[/i] Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0