We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to allocate memory which I can use as a two dimensional array. But the following code is not working
unsigned char xdata ** memo; unsigned char i = 0; // n is number of rows // size is number of columns memo = (unsigned char xdata **) malloc( n*2 ); for ( ; i < size; i++) memo[i] = (unsigned char xdata *)malloc( size );
memo = new char * [n]; for (int i=0; i < n; i++) memo[i*2] = new char [size];
Technically, I need an array of pointers(char **) Do you need to allocate the array AND the stuff that the array objects point to? If so, then... Since you're using malloc to allocate the array of pointers, you need a pointer to the array:
char xdata * xdata *PtrtoPtrs;
PtrtoPtrs = malloc (100 * sizeof (char xdata *));
char buffer [50]; // contains string to add to table for (i=0; i<100; i++) { get_the_next_string(buffer); PtrToPtrs[i] = malloc(strlen(buffer)+1); if (PtrToPtrs[i] != NULL) strcpy (PtrToPtrs[i], Buffer); }
I have two applications, notepad & phonebook Both excellent applications for a microprocessor, how come you have chosen a microcontroller? Erik
"Both excellent applications for a microprocessor, how come you have chosen a microcontroller?" He mentioned the word 'client'. Enough said?
If you have to wrestle this into a '51, why not define the variables in the areas you want to malloc as C externs and use a small assembler module to define the locations. That way you can greb what you need to grab and leave the rest to the compiler. Erik Ps are you related to Abdul Rauf, whom we see now and then in the '51 fora?
Thanks a lot Jon, it really helped me...
RE: Erik why not define the variables in the areas you want to malloc as C externs ... that sounds like a good idea...but honestly I don't know how to do that...but I'll think over it...thanks are you related to Abdul Rauf... Well, I'm not related to the Abdul Rauf you are talking about...but my father's name is also Abdul Rauf who could not be here cuz he is a biologist :)