Link to home
Start Free TrialLog in
Avatar of beyonddeath
beyonddeath

asked on

file i/o

heres my delema, ive got the name of a file in a string, not including the directory.  What i need to do is open that file but it is in another directory for example here is a senario...

char file[20] = "filename.txt";
FILE * file2 = fopen(("//dir//%s",file),"w");

but alls that does is open the file in the current directory...

Thanks for any help...
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

(I should also mention that for more complex formating, you could use sprintf() to create the "final" string, but in this case, a strcpy() and strcat() are sufficient, and probably more efficient than sprintf().

However, the best way to handle this is to move to C++.  In C++ you should almost always use string classes instead of C-style (character array)  strings.  These are far safer and far easier to use.  You could write uour own or use the STL string class, or a string class from another source.  Similarly you should use the C++ file stream objects (fstream) in place of C I/O streams.  These are also far safer and more powerful than C I/O streams.

for example;

string Location = "\\Dir\\";
string File = "filename.txt";
string Path = Location + File;
ofstream File2(Path.c_str());
Avatar of beyonddeath

ASKER

Thats what i thought just couldnt remember the functions strcpy and strat ;)

THANKS
works great as long as winsock will send stuff right always that 50/50 chance of it not sending what i tell it too stupid stupid stupid but this loads everything great!