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 


C++ File Output
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Mon Jan 19, 2009 12:05 am    Post subject: C++ File Output Reply with quote

how would i go about loading "password.txt" into a char* one letter/number at a time?

i have this code, but it reads all of the file(file is only one line around 32 characters). i thought about using hte get function but char* doesnt work with it(from what i tried)


Code:
int nsize = 32;
      char* passwds = new char[32];
      ifstream myfilea;
      myfilea.open("password.txt");
      myfilea.read(passwds,nsize);
      myfilea.close();


thanks for any help =]
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Mon Jan 19, 2009 12:33 am    Post subject: Reply with quote

http://cplusplus.com/doc/tutorial/files.html

Look at the seekg() and seekp() section

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Mon Jan 19, 2009 1:15 am    Post subject: Reply with quote

Create a loop and just read one char at a time. It would be better to just find out the size and only use read once.

Code:

char * passwds = new char[32];

   for (int i = 0; i < 32; i++)
      passwds[i] = 0;

   std::ifstream iFile("password.txt", std::ios::in);
   
   char * ptrPasswds = passwds;
   while(!iFile.eof())
      iFile.read(ptrPasswds++, 1);

   iFile.close();
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Jan 19, 2009 7:36 am    Post subject: Reply with quote

Why to read one char at a time? It's not very wise.. Why not to read the whole block and then do your stuff one char at a time when it's loaded into mem?

File I/O is _slow_, so it's always better to read a little larger block of data than one byte.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 19, 2009 8:28 am    Post subject: Reply with quote

dont forget to delete what you call new on

killersamurai wrote:
Create a loop and just read one char at a time. It would be better to just find out the size and only use read once.

Code:

char * passwds = new char[32];

   for (int i = 0; i < 32; i++)
      passwds[i] = 0;

   std::ifstream iFile("password.txt", std::ios::in);
   
   char * ptrPasswds = passwds;
   while(!iFile.eof())
      iFile.read(ptrPasswds++, 1);

   iFile.close();

_________________
Back to top
View user's profile Send private message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Mon Jan 19, 2009 4:43 pm    Post subject: Reply with quote

i found out c++ has a substr function, unfortuantly it works only for strings. how would i make it work with char* ?

my attempt is below, Note that i want it to read one char at a time, and the TypeStr function only accepts char*

Code:
      int nsize = 32;
      char* passwds = new char[32];
      ifstream myfilea;
      myfilea.open("password.txt");
      myfilea.read(passwds,nsize);
      myfilea.close();
      char* cha = new char[1];
      int i;
      for(i = 0; i <= strlen(passwds); i++)
      {
         cha = passwds.substr(i,i+1);
         TypeStr(cha);
         Sleep(1000);
      }


and these are my compile errors

Code:
.\main.cpp(93) : warning C4018: '<=' : signed/unsigned mismatch
.\main.cpp(95) : error C2228: left of '.substr' must have class/struct/union
        type is 'char *'
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 19, 2009 5:45 pm    Post subject: Reply with quote

Well the warning is telling you exactly whats wrong. Your comparing a signed integer to a unsigned integer. Because you initialized i as an int, while strlen returns an unsigned int.

Second is because char * isn't a struct/class/union. You are confusing yourself with the type string, which is a class that deals with characters for you. It has inline functions like that. Anyways your better off just doing something like this:

Code:
BOOL GetPassword(__in_z LPTSTR lpFileName, __out_z LPTSTR lpPassword)
{
   HANDLE  hFile;
   DWORD   dwSize, dwBytesRead;
   BOOL    bRET = FALSE;

   if (lpPassword != NULL)
   {
      hFile = CreateFile(lpFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
         dwSize = GetFileSize(hFile, 0);
         if (dwSize != INVALID_FILE_SIZE)
         {
            if (ReadFile(hFile, (LPVOID)lpPassword, dwSize, &dwBytesRead, 0))
            {
               if (dwBytesRead == dwSize)
                  bRET = TRUE;
            }
         }
         CloseHandle(hFile);
      }
   }
   return bRET;
}

_________________
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Tue Jan 20, 2009 2:39 pm    Post subject: Reply with quote

lurc wrote:
Well the warning is telling you exactly whats wrong. Your comparing a signed integer to a unsigned integer. Because you initialized i as an int, while strlen returns an unsigned int.

Second is because char * isn't a struct/class/union. You are confusing yourself with the type string, which is a class that deals with characters for you. It has inline functions like that. Anyways your better off just doing something like this:

Code:
BOOL GetPassword(__in_z LPTSTR lpFileName, __out_z LPTSTR lpPassword)
{
   HANDLE  hFile;
   DWORD   dwSize, dwBytesRead;
   BOOL    bRET = FALSE;

   if (lpPassword != NULL)
   {
      hFile = CreateFile(lpFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
         dwSize = GetFileSize(hFile, 0);
         if (dwSize != INVALID_FILE_SIZE)
         {
            if (ReadFile(hFile, (LPVOID)lpPassword, dwSize, &dwBytesRead, 0))
            {
               if (dwBytesRead == dwSize)
                  bRET = TRUE;
            }
         }
         CloseHandle(hFile);
      }
   }
   return bRET;
}


Yes because he totally asked for win32.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Jan 20, 2009 10:28 pm    Post subject: Reply with quote

crayzbeef wrote:
lurc wrote:
Well the warning is telling you exactly whats wrong. Your comparing a signed integer to a unsigned integer. Because you initialized i as an int, while strlen returns an unsigned int.

Second is because char * isn't a struct/class/union. You are confusing yourself with the type string, which is a class that deals with characters for you. It has inline functions like that. Anyways your better off just doing something like this:

Code:
BOOL GetPassword(__in_z LPTSTR lpFileName, __out_z LPTSTR lpPassword)
{
   HANDLE  hFile;
   DWORD   dwSize, dwBytesRead;
   BOOL    bRET = FALSE;

   if (lpPassword != NULL)
   {
      hFile = CreateFile(lpFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
         dwSize = GetFileSize(hFile, 0);
         if (dwSize != INVALID_FILE_SIZE)
         {
            if (ReadFile(hFile, (LPVOID)lpPassword, dwSize, &dwBytesRead, 0))
            {
               if (dwBytesRead == dwSize)
                  bRET = TRUE;
            }
         }
         CloseHandle(hFile);
      }
   }
   return bRET;
}


Yes because he totally asked for win32.


He also never stated he didn't want Win32 Rolling Eyes.
You do know that those classes will make calls to CreateFile, ReadFile, etc. anyways.
Seriously what the fuck is your problem, literally every post you make is aggressive or just stupid.

_________________
Back to top
View user's profile Send private message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Wed Jan 21, 2009 12:36 am    Post subject: Reply with quote

its ok guys, no need to argue, i appreciate both of your replies, so thanks! =]
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Wed Jan 21, 2009 1:38 am    Post subject: Reply with quote

lurc wrote:
crayzbeef wrote:
lurc wrote:
Well the warning is telling you exactly whats wrong. Your comparing a signed integer to a unsigned integer. Because you initialized i as an int, while strlen returns an unsigned int.

Second is because char * isn't a struct/class/union. You are confusing yourself with the type string, which is a class that deals with characters for you. It has inline functions like that. Anyways your better off just doing something like this:

Code:
BOOL GetPassword(__in_z LPTSTR lpFileName, __out_z LPTSTR lpPassword)
{
   HANDLE  hFile;
   DWORD   dwSize, dwBytesRead;
   BOOL    bRET = FALSE;

   if (lpPassword != NULL)
   {
      hFile = CreateFile(lpFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
         dwSize = GetFileSize(hFile, 0);
         if (dwSize != INVALID_FILE_SIZE)
         {
            if (ReadFile(hFile, (LPVOID)lpPassword, dwSize, &dwBytesRead, 0))
            {
               if (dwBytesRead == dwSize)
                  bRET = TRUE;
            }
         }
         CloseHandle(hFile);
      }
   }
   return bRET;
}


Yes because he totally asked for win32.


He also never stated he didn't want Win32 Rolling Eyes.
You do know that those classes will make calls to CreateFile, ReadFile, etc. anyways.
Seriously what the fuck is your problem, literally every post you make is aggressive or just stupid.


Oh sorry for me getting mad when every C++ topic i see people reply with win32 shit.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jan 21, 2009 3:07 am    Post subject: Reply with quote

I am glad that your skills are at a level of which is completely incomprehensible to us mere plebes.

So why have I never seen one useful post coming from you? Or any code for that matter?
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Wed Jan 21, 2009 3:37 am    Post subject: Reply with quote

Quote:
Oh sorry for me getting mad when every C++ topic i see people reply with win32 shit.


that couldnt possibly be cos thats what most people seem to use, and understand

_________________
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Wed Jan 21, 2009 1:45 pm    Post subject: Reply with quote

Snootae wrote:
Quote:
Oh sorry for me getting mad when every C++ topic i see people reply with win32 shit.


that couldnt possibly be cos thats what most people seem to use, and understand


Then why are they replying to a C++ topic posting it.

slovach wrote:
I am glad that your skills are at a level of which is completely incomprehensible to us mere plebes.

So why have I never seen one useful post coming from you? Or any code for that matter?


Maybe because all the shit here is hacking? I just visit here to see if any intelligent things are being programmed. Nothing yet.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jan 21, 2009 2:37 pm    Post subject: Reply with quote

Are you stupid? Like really... Win32 is just using Window API in C++. It is still using the C++ language.
Which all classes do, with the exception of the CRT. They act as wrappers!

Then if you think your so high and mighty how about you use your unbelievably stupid intelligence and program something so impressive that will knock us off our feet.

Yea, come back and call all this shit when you can prove you know something Rolling Eyes.

_________________
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
Goto page 1, 2  Next
Page 1 of 2

 
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