Using Null-Terminating string filenames

Started by
3 comments, last by BeanDog 23 years, 12 months ago
Remember how for a long time I was beggin someone to show me a string-input DX-based routine? Well, I made one. If you want it, you can e-mail me at benbeandogdilts@cs.com. Now that I have that working, I have a pointer to this data: level1.bwc''\n''cdsjcpody8sa0432o1;nk, jdosa7f89a jdska;cd which, when I interpret it, just means "level1.bwc". How do I use this data to open up an ofstream or ifstream object? Say my variable is a LPSTR named filename. If the LPSTR points to the above data, and I try to open a file, it doesn''t work for some reason. Should it? Any suggestions? ~BenDilts( void ); Come to my Web Site at www.geocities.com/benbeandogdilts. At my downloads page you will find SQUIRMS V1.02!!! GRAB IT AND TELL ME IF YOU LIKE IT!!! p.s. some reports say it doesn''t work on some systems. Let me know. Bean Dog
Advertisement
Strings in C are generally null-terminated. So you must replace ''\n'' with ''\0'', then it should work.

Visit our homepage: www.rarebyte.de.st

GA
Visit our homepage: www.rarebyte.de.stGA
You are a godsend. I''ve been working on that problem for months. BTW, how do you check if a file exists? For file loads, of course.
A simple way:

ifstream file(filename);
if (!file)
{
// It''s not here, or something is wrong.
}

The !operator is overloaded to call the fail() function. Look into the basic_ios::good/eof/fail/bad functions in your docs if you want more detail. Depending on your implementation, you may need an ios::nocreate flag in your file constructor or open() call to stop it making the file if it''s not there. However, I believe this flag is now nonstandard and deprecated.
Or, you can look up _access(). That function will tell you if a file exists, and it''s access permission level (read only, etc...)

This topic is closed to new replies.

Advertisement