Hi all!
I''m writing a Breakout-clone in C/C++ using DirectX7. I want to load each level (i.e a 20x20 array with numbers from 0 - 7 defining the type and color of the block) from a file. I use fopen() to read the file from the disk. If i supply the function with a filename "Level0.dat" it works great!
The problem is that I would like to use a global variable that stores my current level, and load the right level for it. Say that I finished level 11 and want to load level 12. Then i would make fopen() read Level12.dat. And if I''m on level 43. fopen() would read in Level44.dat into the array (You get the picture right :-)
If I would try to write "Level%d.dat",G.currLevel instead of a constant string into the function. The compiler wines that the function doesn''t take three parameters. So I tried it another way.
fopen() takes a const char* filename. If I write something like this:
const char* szFilename;
szFilename = "Level%d.dat",G.currLevel;
You see what I''m trying to do?
The problem is that I''m not really sure why this isn''t working. Can you tell me what''s wrong. What is the right syntax for the problem I am trying to solve. I hope you guys are willing to help me out on this one.
Thanks in advance
/ GoomfGoomfDweeda
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn''t become what you should..."
Problems with loading a file...
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn't become what you should..."
"You have to be who you are, when you didn't become what you should..."
Oh. I forgot...
Finally i supply the function with my variable szFilename, but I get all kinds of errors...
Finally i supply the function with my variable szFilename, but I get all kinds of errors...
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn't become what you should..."
"You have to be who you are, when you didn't become what you should..."
Try this:
-Neophyte
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com
char szFilename[128];sprintf (szFilename, "Level%d.dat", G.currLevel);FILE* levelFile = fopen(szFilename);
-Neophyte
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com
Thanks! I''ll try that as soon as I can!
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn''t become what you should..."
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn''t become what you should..."
GoomfGoomfDweeda (Well, what can I say ? All other cool names are busy!)
"You have to be who you are, when you didn't become what you should..."
"You have to be who you are, when you didn't become what you should..."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement