• 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
DominicHughes

How to convert a vector <char> to a const char?

16 posts in this topic

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3]Hello I'm having troubles doing conversions of vectors and chars [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img].[/size][/font][/color]

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3]Heres my vector:[/size][/font][/color]

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3][CODE]vector<char> file_data; [/CODE][/size][/font][/color]

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3]Heres my const char array :[/size][/font][/color]

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3][CODE]const char file_char;[/CODE][/size][/font][/color]

[color=#000000][font=verdana, arial, helvetica, sans-serif][size=3]How do I convert it??.[/size][/font][/color] Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
That doesn't make a lot of sense. A vector<char> contains potentially multiple characters. Why would you want to convert it to a single character?
0

Share this post


Link to post
Share on other sites
oh a const char array [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] so I can access it using operator [ ] Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
Vectors can already be accessed with operator [].
0

Share this post


Link to post
Share on other sites
My wavefront .obj parser needs a const char *filename before it will parse the data as triangles on the screen. so conversion of the vector <char> to const char array is important in this case:

[CODE]
dir=opendir("Box Storage");
if(dir)
{
while(drnt = readdir(dir))
{
// printf("%-20s ", drnt->d_name);
file_list.push_back(drnt->d_name);
}

cout << "found the following files:\n";
for(int i = 0; i < file_list.size(); i++)
{
// cout << file_list[i] << "\n";
}

map<string, vector<char> > files;
for(int i = 0; i < file_list.size(); i++)
{


//load file_list[i] into file_data[i] with fread etc...

files[file_list[i]] = file_data;

}

//cout << "file data "<< &file_data[0] << endl;
//const char* file_char = &file_data[0];

//THIS WON'T WORK :)
loadObject(file_data[0]);


// loadObject(file_data);


}
[/CODE] Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
&file_data[0] will give you a pointer to the first element of the vector, which you should already know since it shows up in your commented out code.
0

Share this post


Link to post
Share on other sites
exactly thats why it won't work because its an element of the vector .

What I need is a filename from the const char array .

To do that I need to convert the vector with index 0 to a const char array so the filename which is contained within the const char array is the first file in the directory box storage.

My problem is how to do the above ^^.


Sorry if my responses are vague or weirdly constructured. Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
A vector is a dynamic array. A pointer to the first element of a vector is a pointer to an array of the type the vector stores. Pointers to a char array can be treated as a pointer to a const char array.
0

Share this post


Link to post
Share on other sites
then if thats the case why is my parser returning that it can't open up the filename? most likely because the vector doesn't contain the filename in which case how is that possible.? is it because I maped the data to memory because if so then that makes everything alot worser.

[CODE]
map<string, vector<char> > files;
[/CODE] Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
Likely candidates are because your vector doesn't contain the data you think it does, the working directory isn't what you think it is and/or you didn't null terminate the vector data. Without more information, it's impossible to say definitively what your problem is.
0

Share this post


Link to post
Share on other sites
What is file_data? A vector of chars? Why can't it hold strings to pass into the loadObject function? Does this not compile, or will it just not load the filename?

If it does compile, make sure the data in file_data is what you think it should be.

This part also doesn't make a whole lot of sense to me
[code]
//load file_list[i] into file_data[i] with fread etc...
files[file_list[i]] = file_data;
[/code]

You aren't loading file_list into file_data. If this is what you have, file_data has nothing inside it, because you aren't assigning things correctly.
0

Share this post


Link to post
Share on other sites
If loadObject() expects a file name as a parameter, why bother loading the file yourself?

However, most such APIs will provide a mechanism for performing the operation in memory. Look at the documentation for this library, discover if it handles this and use that mechanism for your manually loaded data. Obviously, this is more work for you so unless there is some benefit - e.g. storing all the files in a compressed archive - I would just use the handy "load a file contents directly" method.
0

Share this post


Link to post
Share on other sites
this is all rather confusing :( I'm having trouble making a idea of how to solve this from all the different answers..
0

Share this post


Link to post
Share on other sites
I could rewrite this directory reader then just get the filenames from the directory reader and store it in a vector to use as a filename with the [ ] operator?

because the vector is a dynamic array thankfully. Edited by DarkHorseKnight
0

Share this post


Link to post
Share on other sites
It seems as though no one in this thread is on the same page, but yes.
[code]
std::vector< std::string > file_name;
file_name.push_back( "C:\Dev\LOADME.obj" );
loadObject( file_name[0] );

// If the above needs a const char * parameter,
// and you don't want to change the definition:
loadObject( file_name[0].c_str() );
[/code]

I hope this is closer to what you need.
1

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