V
V
VBKesha2014-07-14 14:50:29
C++ / C#
VBKesha, 2014-07-14 14:50:29

How to assign the address of a two-dimensional array to a pointer?

The program has a memory area in which data is stored, the area looks like:
char strings[255][100];
I know the address of the strings variable. Help me describe a copy of a variable and assign an address to it, I was able to get a result close to what I needed with such a perversion:

struct strs{
    char str[100];
};
struct strs *str= (struct strs*)0xDEADBEEF;

And in general, it works, but it looks extremely ugly, and accessing the lines is inconvenient.
Tried like this:
char *test[255][100] = (char *[255][100]) 0xDEADBEEF;

error C2440 : 'type cast' : cannot convert from 'const int' to 'char *[255][100]'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2014-07-14
@VBKesha

char *test[255][100] is a two-dimensional array of pointers to char.
But char (*test)[255][100] is a pointer to a two-dimensional char array, can you feel the difference?
For your question:
char (*test)[100] = (char (*)[100]) 0xDEADBEEF;

G
GavriKos, 2014-07-14
@GavriKos

@GavriKos no, I need a convenient way to access data located in the specified area.

Umm.. char* array = - here's a pointer to the beginning of the array. From there, you already subtract based on the structure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question