Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Krisc

text file operations in the class LOG functions

This topic is 5825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am using the Shining3D engine and modifying it a whole lot and I was wondering some things. Is there anyway to clear a txt file with the way you are working with text files. I have only used fstream.h, not stdio.h, and either way, I do not know how to clear the text file. I want it to clear so that the log will update the text file, not add to it. I want to do that or add the date to it, does anyone know either, or both? Thank you to anyone who helps! [BTW, I''m new here =)] <- http://www.digitalexplosions.com -> "Discipline is my sword, faith is my shield do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

Share this post


Link to post
Share on other sites
Advertisement
I am not sure exactly what you want to do.
But what i got from the email was that you want to earse a text file and then write to it. Not write to it each time in addition to the previous logs in the file.

tell me if i am wrong and i will post another piece of code:


one way to do it with stdio.h is:

#include <stdio.h>

//blah blah blah


//remove(FilePath); --No need, when you use "w" it writes to the file without appending it to the end of it. you use "a" to append text to the end of the file. "w" deletes its contents than writes to it

FILE *hLogFile;

hLogFile = fopen(FilePath, "w");

if(hLogFile)
fputs("Ha, i am writing to the log!", hLogFile);

fclose(hLogFile);


well. that is one way to do it. there are so many way, i mentioned to ways above, just by using "w" to do it or maybe delete the file than make a new one and write to it.
I hope that helped..

Share this post


Link to post
Share on other sites
Thank you so much, I found the line of code and it was already opening it with "wb" and I actually changed my mind and went with "ab"! Thank you though, for now I know more!

EDIT:
Just one thing... fclose(hLogFile); generates an error, an access violation and I have no clue why!?

<- http://www.digitalexplosions.com ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

[edited by - Krisc on December 4, 2002 10:24:39 PM]

Share this post


Link to post
Share on other sites
Ok, well I wrote this code...

// Gets the build number
char *BuildNo;
FILE *hBuildFile;
hBuildFile = fopen("build.txt", "r");
if(hBuildFile)
{
fgets(BuildNo,20,hBuildFile);
}
fclose(hBuildFile);

// Output the build number
S3Dlog.Output("Build Number:");
S3Dlog.Output(BuildNo);

S3Dlog is the LOG class which outputs it to the log file, what I am now trying to do is read a single string from a file, and then close it...

Share this post


Link to post
Share on other sites
Ok, well I wrote this code...

// Gets the build number
char *BuildNo;
FILE *hBuildFile;
hBuildFile = fopen("build.txt", "r");
if(hBuildFile)
{
fgets(BuildNo,20,hBuildFile);
}
fclose(hBuildFile);

// Output the build number
S3Dlog.Output("Build Number:");
S3Dlog.Output(BuildNo);

S3Dlog is the LOG class which outputs it to the log file, what I am now trying to do is read a single string from a file, and then close it...

EDIT: Sorry bout the double post!

EDIT 2: P.S. If any of you would like to contact me, im on MSN Messenger as KriscSC@MSN.COM and AIM as KriscXBL!

EDIT 3: Ok, I have narrowed it down to being something with the declaration of char *BuildNo ...when I re-build it gives me a warning about not setting it up, of course char * types are new to me, just today, so please help if you can! Thank You!

EDIT 4: Well, no one has responded and I cannot fix it, I will check back tomorrow around 9:56 and 10:43, in AP C++ =). So thank you if you help me...ahead of time!

<- http://www.digitalexplosions.com ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

[edited by - Krisc on December 4, 2002 10:33:04 PM]

[edited by - Krisc on December 4, 2002 10:41:40 PM]

[edited by - Krisc on December 4, 2002 10:50:14 PM]

[edited by - Krisc on December 4, 2002 11:07:53 PM]

Share this post


Link to post
Share on other sites
Looks to me like you are trying to read data into a char* that has never been allocated memory. Try something like this instead:

char BuildNo[20];
FILE *hBuildFile;

hBuildFile = fopen("build.txt", "r");
if(hBuildFile)
{
fgets(BuildNo,20,hBuildFile);
}

Share this post


Link to post
Share on other sites
Well.
it gives you an error at char *BuildNu because you are using a pointer to a string with a function that might not be using that as an argument.
also you mmay need to delcare entitys of BuildNu using malloc or new or something.
but that probley isnt it because characters are automatically made pointers to chars when you make them.
or is that with character arrays.
i forget.
just do
char BuildNu[20];
in place of
char *BuildNu;

with 20 being the amoutn of characters that the string is or an close estimate.

try that.

Share this post


Link to post
Share on other sites
Great, thank you so much! Does anyone know how to get the build number? If you don''t its ok, I''m going to search for it now!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!