Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problem when reading a file. [Solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Nov 08, 2008 10:23 am    Post subject: Problem when reading a file. [Solved] Reply with quote

Hi. I have made a .ini file but when I tries to read it I always get some weird letters after the word and I don't know why.

I just want it to say "Hello!" without all the extra letters.
Does anyone knows why?
Code:
void ReadINI()
{
   char FileName[50] = "Addresses.ini";
   char* Buffer;
   FILE* File;
   errno_t Err;
   size_t Result;
   long lSize;

   Err = fopen_s(&File, FileName, "rb");
   if(File == NULL)
      Exit();
   else
   {
      fseek(File, 0, SEEK_END);
      lSize = ftell(File);
      rewind(File);

      Buffer = (char*)malloc(sizeof(char) * (lSize + 1));
      if(Buffer != NULL)
      {
         Result = fread_s(Buffer, sizeof(char) * lSize, 1, lSize, File);
         if(Result == lSize)
         {
            char Text[50];
            sprintf_s(Text, "%s", Buffer);
            MessageBoxA(NULL, Text, NULL, MB_OK);
         }
      }
      fclose(File);
      free(Buffer);
   }
}


Last edited by TraxMate on Sat Nov 08, 2008 12:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Sat Nov 08, 2008 10:49 am    Post subject: Reply with quote

Take a look there: http://www.codeproject.com/KB/cpp/IniReader.aspx

I would give you my code but i don't have it anymore since i started using regitry :s

_________________
Gone
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Nov 08, 2008 11:35 am    Post subject: Reply with quote

Add a null terminator.
Text[lSize] = NULL;
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Nov 08, 2008 12:23 pm    Post subject: Reply with quote

Thanks Symbol, It is working as it should now.

@GMZorita:
I didn't understand how to use the reading part of it, but thanks for trying to help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites