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++]String Matrix?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Thu Apr 10, 2008 2:40 pm    Post subject: [C++]String Matrix? Reply with quote

I'm not 100% sure they are called matrixs, but this is what one would look like.

Code:
int Matrix[100][100];


Is there even a thing as string matrixs? It work when I compiled this code...

Code:
#include <iostream>
using namespace std;
int main()
{
     char Matrix[100][100];
     return 0;
}


But when I tried to assign it something it won't work.

Code:

#include <iostream>
using namespace std;
int main()
{
     char Matrix[100][100];
     for (int i = 0; i < 100; i++)
    {
          Matrix[100][i] = "Something";
     }
     return 0;
}


What am I doing wrong?

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Thu Apr 10, 2008 2:52 pm    Post subject: Reply with quote

String Matrix[100][100];
if you want it to hold a string

for char,
Matrix[100][i] = 'A';
Should work.
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Thu Apr 10, 2008 3:06 pm    Post subject: Reply with quote

You have the array at 100 , 100. Which the index starts at 0.

Code:

Matirx[99][i] = "Something";


There is another problem. Matrix is declared like this
Code:

char Matrix[100][100];

This only allows you to hold one char. You need to make it a pointer or else you will get an error.

Code:

char *Matrix[100][100] = { 0 };
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Apr 10, 2008 8:24 pm    Post subject: Reply with quote

Firstly since I don't think you fully understand what a matrix is (not trying to insult you just stating what I observed.)
http://en.wikipedia.org/wiki/Matrix_%28mathematics%29

Heres quick example of a string matrix:

Code:
#include <iostream>
#include <string>
#include <vector>

std::string strStringMatrix[10][10];
int main()
{
   char szInput[255] = {0};

   for( int x=0;x<10;x++ )
      for( int y=0;y<10;y++ ){
         sprintf_s( szInput, sizeof(szInput), "Testing %dx%d", x, y );
         strStringMatrix[x][y] = std::string( szInput );
         std::cout << "[" << x << "x" << y << "] " << strStringMatrix[x][y].c_str() << std::endl;
      }

   return 0;
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Fri Apr 11, 2008 4:58 am    Post subject: Reply with quote

HornyAZNBoy wrote:
Code:

#include <iostream>
using namespace std;
int main()
{
     char Matrix[100][100];
     for (int i = 0; i < 100; i++)
    {
          Matrix[100][i] = "Something";
     }
     return 0;
}


What am I doing wrong?
The second dimension is for the letters... Matrix[i] = "Something"; would be a bit more closer, but that doesn't work either, since strings can't be set that way. However this DOES work:
Code:
#include <iostream>
#include <string>

int main(int argc, char **argv)
{
   std::string test[3][3];

   for(int j=0; j<3; ++j)
      for(int i=0; i<3; ++i)
         test[j][i] = "asd";

   for(int j=0; j<3; ++j) {
      for(int i=0; i<3; ++i)
         std::cout << test[j][i] << " ";
      std::cout << std::endl;
   }

   return EXIT_SUCCESS;
}
A bit similar to Wiccaan's code, but w/e :P Of course you could do the printing in the same loop, but IMO this demonstrates a bit better the matrix.

A bit offtopic, since you were talking about matrices, but here's a hint: if you need no more than one dimension (the 2nd one is for the chars) I recommend using std::vector..
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