Hey! I need to make my program to make a directory named Data.
I tried with this:
But it resulted in that the program crashed.Code:system("md Data");
Any help would be appreciated.
Also an explanation of why my program crashes would be cool![]()
Hey! I need to make my program to make a directory named Data.
I tried with this:
But it resulted in that the program crashed.Code:system("md Data");
Any help would be appreciated.
Also an explanation of why my program crashes would be cool![]()
On a windows machine, you should be able to use _mkdir (or _wmkdir if you are using unicode strings).
http://msdn2.microsoft.com/en-us/lib...zw(vs.71).aspx
--
Mats
Okay great thx, I've read the description and it seems like the thing I need.
Just wondering, how do I use it? Haha sorry if being annoying.
But didn't really get it, I guess it's a library I have to include.
so.. do I need to download the header file or is it just like #include <direct.h> or something?
Hmm.. I've tried around a little and commenting in and out stuff in my text and found out that the reason of my program crashing, wasn't cause of the folder creation.
Is it okay for me to post the code here? Or do I need to make a new thread for that?
As it's sort of related, I'd say post it here.
By the way, the above "_mkdir" function is certainly preferrable to the system("md ...") solution, as the latter is much more expensive (it creates a new process, then runs the md command, and exits).
--
Mats
Hmm okay great.
Well here's kinda some background.
I'm 16 years old, going on a Game Developing high school (think I translated that right).
This ain't homework as we don't got this kind of stuff yet, but I'm trying to be ahead of schedule or something.
Well anyway, I'm trying to make a kind of Online Strategy Game, (kinda like the Web based you see all over the web)
And this part is supposed to create the needed files for the "Server". Some of these files is supposed to be placed in a directory called Data.
Code:void install() { /* Create all critical files which is needed to be able to run the server */ /* Create a "Default" settings.xml file*/ FILE *install_file = fopen("settings.xml", "w"); fprintf(install_file, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n", stdout); fprintf(install_file, "<server>\n", stdout); fprintf(install_file, "\t<name>PA-Server01</name>\n", stdout); fprintf(install_file, "\t<version>0.1</version>\n", stdout); fprintf(install_file, "\t<updaterate>1</updaterate>\n", stdout); fprintf(install_file, "</server>\n", stdout); fprintf(install_file, "<admin>\n", stdout); fprintf(install_file, "\t<username>adminstrator</username>\n", stdout); fprintf(install_file, "\t<password>default</password>\n", stdout); fprintf(install_file, "\t<securitykey>00001111 10101010 01010101 11110000</securitykey>\n", stdout); fprintf(install_file, "</admin>\n", stdout); fclose(install_file); /* Create the file for SERVERSTATE*/ install_file = fopen("state.info", "r"); fprintf(install_file, "CLS", stdout); fclose(install_file); /* Create xml list for accounts */ _mkdir ("Data"); install_file = fopen("Data/accounts.xml", "w"); }
I started out with C++, but I learned that C should be faster.
So I'm kinda new to C, but do get some things of it. So my guess is, that it's failing with fclose? And after using fclose with my FILE pointer, I have to create a new pointer?
I haven't looked much at your code, butdoesn't look too good.Code:install_file = fopen("state.info", "r"); fprintf(install_file, "CLS", stdout); fclose(install_file);
Why are you WRITING to a file that is opened for reading? Did you mean "r+"?
What's "stdout" got to do with anything? You are not printing the argument anyways.
You are also not checking any of the fopen() to see if it worked - so if there's a problem, you will probably crash due to accessing a NULL pointer.
Finally, I don't agree withC or C++ are both compiled languages. If you know roughly what you are doing, the code will be fast. If you don't know what you're doing, the code will not be fast - language has little to do with that. Also, if you know C++, it will help you get the application running faster than if you use a language you don't know.I started out with C++, but I learned that C should be faster.
Sure C++ can easily cause all sorts of slowness because someone don't understand how to write good code (or use the language features in the right way) - it's probably a bit easier to do this wrong in C++ than in C - but neither are "sure to be fast"....
--
Mats
Man I must have missed that "r"! Damn me! Thought I had scanned the whole function after any logical errors made by me. It was supposed to be "w".
And no I'm not testing if it succeeded with opening, because foremost, I'm only planning on letting myself using it. There's no fancy layout for the server so that many different people can use it.
You need to know what to do else you won't be able to work with the server.
And the part with C being faster, a friend told me that which he has said from his own experience.
When C++ uses classes, it has to load those classes from the memory, and list the functions, load them, THEN run the operations in the function. Afterwards it unloads it all again, and etc. etc.
Kinda hard for me to explain, as I don't really know how I'm supposed to translate it from Swedish to English
But this is kinda off-topic, if you want to discuss it you are free to mail me at [email protected]
I think this is a very valid discussion, as it relates to your project and C/C++ is what this forum is about.
When you use a class, it does indeed have a "funciton table" (if you use the virtual keyword) which is used to dereference the methods of that class. But the slowness of C++ is more related to the way that people tend to write code in C++ with functions that call member functions in the base class, and particularly long chains of constructor calls. But if we write C++ in a sensible way, and avoid using methods that cause long chains of calls that eventually does very little, it's not that bad.
If you want to PM me with the Swedish, så kan jag översätta (I'll translate).... ;-)