Author Topic: my little program  (Read 1473 times)

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
my little program
« on: March 05, 2008, 12: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.
« Last Edit: March 05, 2008, 03:16:00 pm by Durwyn »
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

Caarrie

  • Forum Addict
  • *
  • Posts: 3369
  • We want no UNFIXED bugs!!!!!!!!!!!!!
    • View Profile
    • PlaneShift3dMods
Re: my little program
« Reply #1 on: March 05, 2008, 12:02:20 pm »
and it does what?

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #2 on: March 05, 2008, 12:09:41 pm »
copy your logs from one file to another wherever you want ;o
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

steuben

  • Veteran
  • *
  • Posts: 1834
    • View Profile
    • Myspace
Re: my little program
« Reply #3 on: March 05, 2008, 12:11:27 pm »
bah doing better then me. i panic compilers on the "hello world" code.
may laanx frighten the shadow from my path.
hardly because the shadow built the lexx.
the shadow will frighten laanx from my path.

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #4 on: March 05, 2008, 03: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


Looking after
http://pastebin.ca/929467

otherwise i would loved keeping the original one guys :P  :lol:
« Last Edit: March 06, 2008, 03:18:04 pm by Durwyn »
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

Funki Grimalkin

  • Traveller
  • *
  • Posts: 13
    • View Profile
Re: my little program
« Reply #5 on: March 12, 2008, 06:20:21 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)

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
Meow & Regards !
Funki Grimalkin

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #6 on: March 13, 2008, 08:08:15 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)

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:
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

Funki Grimalkin

  • Traveller
  • *
  • Posts: 13
    • View Profile
Re: my little program
« Reply #7 on: March 13, 2008, 09:01:22 am »
That thread was a good read ! Nice tip off Dudu !
Moreover I now have a "cunning plan" for my own tool !


Meow & Regards !
Funki Grimalkin

Kemex

  • Traveller
  • *
  • Posts: 24
  • - If can be done, then i will code it -
    • View Profile
Re: my little program
« Reply #8 on: April 21, 2008, 11:13:30 am »
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:

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #9 on: April 21, 2008, 02: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
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

Kemex

  • Traveller
  • *
  • Posts: 24
  • - If can be done, then i will code it -
    • View Profile
Re: my little program
« Reply #10 on: April 21, 2008, 02: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:











Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #11 on: April 21, 2008, 03:40:35 pm »
eh nananananana xP  8)
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin

Tuxide

  • Hydlaa Notable
  • *
  • Posts: 715
    • View Profile
    • Banker
Re: my little program
« Reply #12 on: April 21, 2008, 03:49:37 pm »
Why are you including windows.h?

Waylander

  • Veteran
  • *
  • Posts: 1562
  • Constantly correct since 1988
    • View Profile
Re: my little program
« Reply #13 on: April 21, 2008, 04: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...)
* Waylander goes hunting for his USB key :P

Either way, keep interested :)
<Jeraphon>oh khado
<Jeraphon>you so khrazy

Xil|sleeps: I love cadoras

Waylander, A.K.A: Cadoras, Khado, Nurahk, Armeen, Nostra ... God.

Durwyn

  • Hydlaa Citizen
  • *
  • Posts: 301
    • View Profile
    • Athénée Royal Jean Rey Couvin
Re: my little program
« Reply #14 on: April 22, 2008, 06:47:01 am »
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//
http://arjrcouvin.jimdo.com/
Athénée Royal Jean Rey Couvin