PlaneShift
Fan Area => The Hydlaa Plaza => Topic started by: Durwyn on March 05, 2008, 06:01:03 pm
-
im really proud of it.. really in 7 months of studying its the best i made till now ;) \\o// took me 2 hours because im still learning :sweatdrop:
Here is the code: (C++)
#include <stdio.h>
#include <windows.h>
int main(void)
{
FILE *streamOut;
FILE *streamIn;
streamOut = fopen("C:\\Users\\ben\\AppData\\Roaming\\PlaneShift\\logs\\Durwynlog.txt", "wt"); //where you want to save it to.
streamIn = fopen("C:\\Users\\ben\\AppData\\Roaming\\PlaneShift\\logs\\Durwyn_chat.txt", "rt");//source file.
char buffer[1024];
int bytesRead;
do
{
bytesRead = fread(buffer, 1, 1024, streamIn);
fwrite(buffer, 1, bytesRead, streamOut);
}
while(bytesRead==1024);
system("pause");
fclose(streamOut);
fclose(streamIn);
return 0;
}
what do you think of? :whistling: thought i would share it :)
(PS: i have no idea of where this thread has to be :-X)
Edit: (keeping all informations here)
adding some informations to answer all mails:
yes, this program will permits to the logs to look like they were before and not as they do look like now.
-
and it does what?
-
copy your logs from one file to another wherever you want ;o
-
bah doing better then me. i panic compilers on the "hello world" code.
-
adding some informations to answer all mails:
yes, this program will permits to the logs to look like they were before and not as they do look like now.
Looking Now
(http://dudu.110mb.com/before.JPG) (http://dudu.110mb.com/before.JPG)
Looking after
http://pastebin.ca/929467
otherwise i would loved keeping the original one guys :P :lol:
-
8) Good work DuDu ! :thumbup:, now its time for nit picking ! :devil:
I mean, more like suggestions for improvements :detective:
1. streamOut & streamIn could be NULL (what happens if file does not exist ?, null file pointers are returned with fopen & program dies)
2. better be using feof instead of bytesread to stop the while loop..(end of file & error flags)
3. Declare variables closer to their usage (which is more c++, unlike c, where variables are generally declared before code execution blocks)
Modified version below :). (Uncompiled & unverified !)
#include <stdio.h>
#include <windows.h>
int main(void)
{
// TODO
char strOutputFileName[MAX_PATH] = collect from user; // argv/c
char strInputFileName[MAX_PATH] = collect from user;
FILE *streamOut = = fopen(strOutputFile, "wt"); //where you want to save it to.
FILE *streamIn = fopen(strInputFile, "rt");//source file
if((streamOut != NULL) && (streamIn != NULL))
{
char buffer[1024];
while(!feof(streamIn) && (!ferr(streamIn))
{
int bytesRead =fread(buffer, 1, 1024, streamIn);
fwrite(buffer, 1, bytesRead, streamOut);
}
system("pause");
fclose(streamOut);
fclose(streamIn);
}
else
{
// error, couldnt open file..boo hooo !
}
return 0;
}
I now demand a share of any income you get from this program ... ;D
-
8) Good work DuDu ! :thumbup:, now its time for nit picking ! :devil:
I mean, more like suggestions for improvements :detective:
1. streamOut & streamIn could be NULL (what happens if file does not exist ?, null file pointers are returned with fopen & program dies)
2. better be using feof instead of bytesread to stop the while loop..(end of file & error flags)
3. Declare variables closer to their usage (which is more c++, unlike c, where variables are generally declared before code execution blocks)
1. i made the program in order to move the log file where ever i want, so the file exist. :P
2. you are right. :-[
3. im studying C for the moment. C++ is only next year. :-[ if i get used to put all the variables near their usage i will get a big 0 at the exam ;)
I now demand a share of any income you get from this program ... ;D
i just unlike/hate the fact that the user must put the file's path himself via a MS-DOS window.. (because its how it launchs to right now)
It hurts me to type all the files paths (source and destination) .. thats why i prefered to keep these variables out of the use for the User.
anyways i would love to keep that idea (i mean the one that the user put the filepath) , IF and only IF, there would be a basic interface (?) for the user. like a small popup which would ask for the filename with a "Search" button which permits to search the file name manually on the Computer/hard disk.
i will "nit pick" (to take your expression :) ) an old program that Balonik made (PSMsgBell if you know)
he put an interface in it, i will try to master his program ,at least understand it XD , before trying to modify mine. ;)
Note :thread about Balonik's program: http://hydlaa.com/smf/index.php?topic=25473.0
Thanks Funki :lol:
-
That thread was a good read ! Nice tip off Dudu !
Moreover I now have a "cunning plan" for my own tool !
-
Erm... i dislike to be cruel... but...:
- What does happen, if you cut/copy & paste ?
- What does happen, if you use Shell/Batch script instead of Compiled program ?
- What does happen, if you never heard about compiling your own program ?
but.. anyway.. nices doing. :sweatdrop:
-
What does happen, if you cut/copy & paste ?
if you copy paste it on a Compiler and click on "Compile and Execute" it will give an Exe which will work without any problems on Windows. :)
What does happen, if you use Shell/Batch script instead of Compiled program ?
i dont know what sort of scripts your talking about, all i can say is that you will have to re-do your own code for that script :)
What does happen, if you never heard about compiling your own program ?
some clicks from there to there..you will need at least 5 mins to make the program :P lol
http://www.bloodshed.net/devcpp.html use the program Dev C++ to compile the program.
copy paste the code in a "new document", click Compile and Execute and you will have it :)
post your questions if needed
-
Sorry Durwyn, plz dont take it personal (i know the programmer's spirit we all have inside), but it is a little "messy" to make a program just to do something that we can resume in a single copy/paste.
That's is the reason that Script's does exist's... to simplify user actions that doesnt require a compiled program (potencially a virus target).
About Scripting..
Google the following:
Linux Shell Scripting tutorial (also available for windows via cygwin). (Also apply to All Unix's like OS )
Batch Script for Windows (doesnt avaible to Linux lol)
If u really want to learn C/C++ better start with things like try to make an Offline Parsing Log utilitys (also you can do this via shellscript, but its a good point to start codig in c/c++).
Keep doing well :thumbup:
-
eh nananananana xP 8)
-
Why are you including windows.h?
-
Kemex: I think it's more just to practice the language than to make an overly useful program.
Durwyn: What I did when learning C++ was I made a completely useless program (Address book xP) and then would keep adding things I learned to it. Granted, it ended up being an Address Book with more useless features than Addresses :P But, I got to play around with the language. (It had a little game in it, too... such an awesome Address Book...)
/me goes hunting for his USB key :P
Either way, keep interested :)
-
windows.h is useless now i added to print each letter on the screen to know why it wouldnt have save all the lines :lol:
Waylander, its only my first year in C. i only work under MS-DOS xP programming is interesting! :) i prefer html , css and php though xP
its hard to begin learning that once we can do something, we feel so....goood! :oops:
how many years of studies for your program? :) just to know when i will throw away that MS-DOS \\o//
-
YaY to the Programming spirit ! ;D
Also I would expect the compiled .exe in THIS case to be MUCH faster than a script/batch file.
-
Hey Durwyn!
Many Thanks by the NPC's List.. i will implement it tomorrow (I have a busy day today).
I couldn't answer your message since my profile is too new and i cannot send personal messages yet.
If u have any idea that can be implemented to the program, you are welcome, so feel free to send it to: kemexmiraz@gmail.com.
Also you can send it to my inbox here, but i wouldnt answer by the know's reason.
-
I taught myself everything I know. I'm nowhere near proficient enough to help with PlaneShift but, I can hold my own.
I'm going into a Comp Sci program now basically because I need the sheet of paper :P