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

Archived

This topic is now archived and is closed to further replies.

Dharma

Load file

5 posts in this topic

What would you suggest as a simple way of loading strings from a file into names[][] ? I''m working on a simple highscore table in "dos", got the sort and saving routine working but I fail when trying to load the names. Any suggestions? I''m saving the names like this and it works fine
    

    for (count = 0; count < 11; count++)
	fprintf(out, "%s\n", namn[count][0]);


    
Thanks in advance. Mvh Mario..
0

Share this post


Link to post
Share on other sites
what you might need to do is allocate space for the names first, altough looking at your source, you seem to have done this. assuming you have code that looks like this:

char names[11][16]; /* eleven names, up to 16 characters */

then you can rely on the fact that you have 176 bytes of text in the file, and that can be loaded all in one go, by doing this:

fread(&names[0][0], sizeof(char), 11 * 16, pTheFileYouAreUsing);

this will read the charecters straight into your array in one go.

howvever, if you have variable length names, like

char* names[11]; /* eleven POINTERS to string */

you can''t simply load them up from the file, because there is no space for them. if your using c++, do this:

char buffer[255];
for(int i=0; i<11; i++)
{
fscanf(pSomeFileOrOther, "%s\n", buffer);
names = new char[strlen(buffer)];
strcpy(names[i], buffer);
}

this reads eleven strings, allocates space for them.

if this doesn''t work, try using the ''string'' class from the standard library, it is so well written, it can be FASTER than char* strings!
0

Share this post


Link to post
Share on other sites
CString is well written, still it won''t come up to the speed of normal char *. (The standard library for string functions is well written too :p)... So, I think it depend''s on what''s more confortable to somebody.. It''s char * for me :o)

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
0

Share this post


Link to post
Share on other sites
quote:
Original post by davekerr
if this doesn't work, try using the 'string' class from the standard library, it is so well written, it can be FASTER than char* strings!


Even better, use the STL first .

// note that these are C++98 headers!
#include <iostream>
#include <string>
#include <vector>

using namespace std;
vector<string> names;
ifstream file;

void ReadNamesFromFile(char *filename)
{
char temp[80]; // this should be the max line length
file.open(filename);
int j = 0;
while(!file.eof())
{
file.get(temp, 80);
names[j++] = tmp; // increments counter after statement.
}
}


Edit: counter, pointer.

Edited by - Oluseyi on October 19, 2001 5:30:41 PM
0

Share this post


Link to post
Share on other sites
quote:
Original post by phueppl1
CString is well written...

CString is part of MFC; I don''t think that''s what davekerr was talking about.

CString does have certain very nice features that I wish STL string had, though.
0

Share this post


Link to post
Share on other sites
dunno if this is what your after, but this is the method i generally use.....

  
void ReadData(char Filename[20])
{
std::ifstream DATA(Filename);
if(DATA)
{
for(int x=0; x<MAX_SCORES; x++)
{
std::string data;
DATA >> Score[x]
}
}
else
{
cout<<"could not load score data...";
}
}



might not be the best way, probably isnt, but hey! i works for me.

Alan
0

Share this post


Link to post
Share on other sites