PlaneShift

Fan Area => The Hydlaa Plaza => Topic started by: Durwyn on March 05, 2008, 06:01:03 pm

Title: my little program
Post 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++)
Code: [Select]
#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.
Title: Re: my little program
Post by: Caarrie on March 05, 2008, 06:02:20 pm
and it does what?
Title: Re: my little program
Post by: Durwyn on March 05, 2008, 06:09:41 pm
copy your logs from one file to another wherever you want ;o
Title: Re: my little program
Post by: steuben on March 05, 2008, 06:11:27 pm
bah doing better then me. i panic compilers on the "hello world" code.
Title: Re: my little program
Post by: Durwyn on March 05, 2008, 09:15:01 pm
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:
Title: Re: my little program
Post by: Funki Grimalkin on March 13, 2008, 12:20:21 am
 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 !)

Code: [Select]
#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
Title: Re: my little program
Post by: Durwyn on March 13, 2008, 02:08:15 pm
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  ;)

Quote
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:
Title: Re: my little program
Post by: Funki Grimalkin on March 13, 2008, 03:01:22 pm
That thread was a good read ! Nice tip off Dudu !
Moreover I now have a "cunning plan" for my own tool !


Title: Re: my little program
Post by: Kemex on April 21, 2008, 06:13:30 pm
Erm... i dislike to be cruel... but...:


but.. anyway.. nices doing.  :sweatdrop:
Title: Re: my little program
Post by: Durwyn on April 21, 2008, 09:04:08 pm
Quote
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. :)

Quote
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 :)

Quote
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
Title: Re: my little program
Post by: Kemex on April 21, 2008, 09:29:33 pm
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:










Title: Re: my little program
Post by: Durwyn on April 21, 2008, 10:40:35 pm
eh nananananana xP  8)
Title: Re: my little program
Post by: Tuxide on April 21, 2008, 10:49:37 pm
Why are you including windows.h?
Title: Re: my little program
Post by: Waylander on April 21, 2008, 11:13:00 pm
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 :)
Title: Re: my little program
Post by: Durwyn on April 22, 2008, 01:47:01 pm
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//
Title: Re: my little program
Post by: Funki Grimalkin on April 24, 2008, 04:15:59 pm
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.

Title: Re: my little program
Post by: Kemex on April 25, 2008, 06:57:30 pm
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.


Title: Re: my little program
Post by: Waylander on April 25, 2008, 07:02:24 pm
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