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 


Reading from a text file and storing in 2-D array

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

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Jan 18, 2009 9:50 pm    Post subject: Reading from a text file and storing in 2-D array Reply with quote

Hey, I need some help reading from a text file that has 100 lines. Each line has a bunch of numbers on it.

What i'm trying to do is read from this text file and store each number (which are separated by spaces) into a 2-D array. This is what I have but it fails in immense amounts (don't laugh please Embarassed )

Code:
void ReadTriangle()
{
   FILE* pFile = fopen( "triangle.txt", "r" );
   int buffer[100][100];

   for( int i = 0; i < 100; i++ )
   {
      for( int n = 0; n < 100; n++ )
      {
         fscanf( pFile, "%i", buffer[i][n] );
      }
   }
}

int main()
{
   ReadTriangle();
   getchar();
}


It obviously doesn't work. Can someone help me?

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sun Jan 18, 2009 10:55 pm    Post subject: Reply with quote

Code:

fscanf( pFile, "%i", &buffer[i][n] );


It's a common mistake not to use the ampersand with a two dimensional array.
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

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

Oh ok. Well i tried it and it still doesn't work. Everything compiles fine but as soon as it compiles I get a "Debug Assertion Error!". Know what it means?
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

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

Only reason I can think of is that the file wasn't found and you're trying to read from something that doesn't exist.
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Mon Jan 19, 2009 10:31 am    Post subject: Reply with quote

So then should putting the txt file in the debug folder when i debug it work?
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

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

If you're using visual studio, it will look in projects > project name > project name. That is assuming you're running the program through visual studio. If you're running the program through cmd, it has to be in the same location as the exe. Unless you specify a location like c:\filenamme.txt. Then you'll have to put the file where ever you specified.
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 7:47 pm    Post subject: Reply with quote

use error checking to see if the file exists or not
_________________
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Mon Jan 19, 2009 11:50 pm    Post subject: Reply with quote

Well I have the text file I want to read from. And I put it in the debug folder. But i still get that message. But if i run the exe not through the compiler then I don't get a message. It's weird Confused
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Tue Jan 20, 2009 2:15 am    Post subject: Reply with quote

If you run it from the compiler, the exe is run from your project folder, not from the debug/release folders.
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Tue Jan 20, 2009 2:33 am    Post subject: Reply with quote

getlines
then process each line with stringstream

_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

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

If you use Microsoft Studio, the program is starting in the <project name> folder if you debug it with the compiler. If you want to debug with the compiler, move the .txt file into the <project name> folder or else, move the file to the debug folder and start your project there (as in double-click the .exe instead of going to the compiler and running it)..
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

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

Yeah thanks I already fixed it. But i need to work on the code because it doesn't seem to be working right
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
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