 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Oct 23, 2007 4:38 pm Post subject: storing buffer in int array |
|
|
say i have a 4 char buffer, how can i put each char into a an array of int. Also how can i access each of these numbers.
so say i want char 3 of int array, so could i just access it using int[2];
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Oct 23, 2007 4:41 pm Post subject: |
|
|
| Thats like trying to input the letter Q into a calculator..
|
|
| Back to top |
|
 |
nox Expert Cheater
Reputation: 0
Joined: 09 Apr 2007 Posts: 227 Location: brooklyn
|
Posted: Tue Oct 23, 2007 4:58 pm Post subject: |
|
|
| it needs to be multi-dimensional
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Tue Oct 23, 2007 5:01 pm Post subject: |
|
|
| Code: |
int i;
char buffer [4];
int array [4];
//populate the char buffer
for (i = 0; i < 4 ; i++){
array[i] = (int)buffer[i];
}
|
That?
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Oct 23, 2007 6:35 pm Post subject: |
|
|
oh i forgot to mention im gonna try to get the value of each number. like
a =1
b = 2
z = 26
_________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Tue Oct 23, 2007 6:57 pm Post subject: |
|
|
| Code: |
int i;
char buffer [4];
int array [4];
//populate the char buffer
for (i = 0; i < 4 ; i++){
array[i] = (int)(buffer[i]|0x20)-'a'+1;
}
|
That?
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Oct 23, 2007 7:56 pm Post subject: |
|
|
| Code: | case WM_HOTKEY:
if(wParam == 1)
{
hEdit = FindWindowEx(hwnd, NULL, "Edit", NULL);
GetWindowText(hEdit, &t, 2);
MessageBox(hwnd, &t, " ", MB_OK);
if( &t == "a")
{
i = value(&t);
MessageBox(0, itoa(i, temp, 10), "Error", MB_OK);
}
}
break; |
| Code: | int value(char* let)
{
if(let == "a")
return 1;
if(let == "b")
return 2;
if(let == "c")
return 3;
if(let == "d")
return 4;
if(let == "e")
return 5;
if(let == "f")
return 6;
if(let == "g")
return 7;
if(let == "h")
return 8;
if(let == "i")
return 9;
if(let == "j")
return 10;
if(let == "k")
return 11;
if(let == "l")
return 12;
if(let == "m")
return 13;
if(let == "n")
return 14;
if(let == "o")
return 15;
if(let == "p")
return 16;
if(let == "q")
return 17;
if(let == "r")
return 18;
if(let == "s")
return 19;
if(let == "t")
return 20;
if(let == "u")
return 21;
if(let == "v")
return 22;
if(let == "w")
return 23;
if(let == "x")
return 24;
if(let == "y")
return 25;
if(let == "z")
return 26;
else
MessageBox(0, "Shit", "Error", MB_OK);
} |
thats my functions. Its checking a char t for a and run the value but for some reason if i put a in and a is in the MB with 2 bytes, it doesn't run the code. Does anyone know why a isn't coming up as a?
sorry im confusing, im tired :[
_________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Tue Oct 23, 2007 8:06 pm Post subject: |
|
|
| you can't use == to compare character arrays, you need to use strcmp or strncmp
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Tue Oct 23, 2007 8:24 pm Post subject: |
|
|
| blankrider wrote: |
| Code: | int value(char* let)
{
if(let == "a")
return 1;
if(let == "b")
return 2;
if(let == "c")
return 3;
if(let == "d")
return 4;
if(let == "e")
return 5;
if(let == "f")
return 6;
if(let == "g")
return 7;
if(let == "h")
return 8;
if(let == "i")
return 9;
if(let == "j")
return 10;
if(let == "k")
return 11;
if(let == "l")
return 12;
if(let == "m")
return 13;
if(let == "n")
return 14;
if(let == "o")
return 15;
if(let == "p")
return 16;
if(let == "q")
return 17;
if(let == "r")
return 18;
if(let == "s")
return 19;
if(let == "t")
return 20;
if(let == "u")
return 21;
if(let == "v")
return 22;
if(let == "w")
return 23;
if(let == "x")
return 24;
if(let == "y")
return 25;
if(let == "z")
return 26;
else
MessageBox(0, "Shit", "Error", MB_OK);
} |
|
Did you completely ignore what I posted? Hint: single quotes around a character represents its ASCII value. You can get an integer value with small 'a' as 1 by subtracting the ASCII value by 'a' then add one.
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Oct 23, 2007 8:41 pm Post subject: |
|
|
You could also compare like this:
| Code: | int GetLetterValue(const char* szLetter)
{
char szAlphabet[27]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
for( int x=0; x<sizeof(szAlphabet); x++ )
if( (int)szAlphabet[x] == (int)szLetter[0] )
return x+1;
return -1;
} |
Comparing the letters numeric value.
_________________
- Retired. |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Tue Oct 23, 2007 8:53 pm Post subject: |
|
|
but would this not be much simpler?
| Code: |
int GetLetterValue(const char* szLetter)
{
if (szLetter[0] >= 'a' && szLetter[0] <= 'z')
return (int)(szLetter[0]-'a'+1);
return -1;
} |
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Wed Oct 24, 2007 2:19 pm Post subject: |
|
|
Ooh, ooh, let me make a suggestion thats way less efficient than Delta Flyer's solution too!
| Quote: | | single quotes around a character represents its ASCII value |
Lie! Single quotes = const char. So you should cast it to int or you'll get *gasp* compiler warnings!
Also, you have to offset it differently for lowercase VS capitals, or do toLower() on them all, because there are some symbols and stuff inbetween the two sets in the ASCII definition.
Anyhow, in the end this is quite silly.
| Code: | char chararray[4];
int intarray[4];
intarray = (int*)chararray;
|
Voila. Although the values in intarray are still the ascii codes rather than in the 1-26 range. But then, why not deal with that when you use them instead? Don't convert all the data and restore it, instead make a macro and convert when you use the values.
| Code: | #define TOALPHOFFSET(x) (int)(x-(int)'a'-1)
printf("%d",TOALPHOFFSET(intarray[2]));
|
~nog_lorp
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Oct 24, 2007 3:41 pm Post subject: |
|
|
| Code: | case WM_HOTKEY:
if(wParam == 1)
{
hEdit = FindWindowEx(hwnd, NULL, "Edit", NULL);
GetWindowText(hEdit, t, sizeof(t));
r = 0;
i = 0;
while(isalpha(t[i]))
i++;
while(r <= i-1)
{
arr[r] = GetLetterValue(&t[r]);
itoa(arr[r], temp, 10);
MessageBox(0, temp, "Error", MB_OK);
r++;
}
int staMatrix[2][2] =
{
arr[0], arr[1],
arr[2], arr[3],
};
finMatrix[2][2] = encMatrix[2][2] * staMatrix[2][2];
// itoa(finMatrix[2][2], buffer[2][2], 10);
// MessageBox(0, (char*)buffer[2][2], "Error", MB_OK);
}
break; |
well i did that and i figured it out and stored the first FOUR digits in a matrix, staMatrix. Im multiplying this by a matrix. It multiplies fine but i can't convert the value to char to display it in a textbox. Any ideas, this is my first encounter with matrices outside of pencil and paper
_________________
|
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Wed Oct 24, 2007 4:15 pm Post subject: |
|
|
Stop thinking about matrices and start thinking about fundamentals. Matrices aren't your problem.
To convert from the alphabetical offset back to characters, do the opposite of GetLetterValue, (char)(num - (int)'a').
Another thing: matrices aren't a type in C. FFS, those are multidimensional arrays, not matrices, you cant just multiply 2 of them and expect C to do matrix multiplication. You are multiplying two array elements.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Oct 24, 2007 4:24 pm Post subject: |
|
|
well i found a code and i made a new type called Matrix
and theres a function called matrixMultiply. And nog, i wasn't there yet...I am just about the make the GetLetterVal function as we speak. I have it so that it works right now.
And Matrices are my problem because i wasn't converting back yet and the problem was in matrix mult.
oh yeah nog you were wrong
char GetNumberValue(int in)
{
return (char)(in + (int)'a' - 1);
}
>.>
_________________
|
|
| Back to top |
|
 |
|
|
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
|
|