Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Creation of install shield Pin
shir_k4-Oct-09 21:24
shir_k4-Oct-09 21:24 
Questionhow to convert char * to char[100] Pin
prithaa22-Sep-09 3:54
prithaa22-Sep-09 3:54 
AnswerRe: how to convert char * to char[100] Pin
Chris Losinger22-Sep-09 4:10
professionalChris Losinger22-Sep-09 4:10 
AnswerRe: how to convert char * to char[100] Pin
Rajesh R Subramanian22-Sep-09 4:30
professionalRajesh R Subramanian22-Sep-09 4:30 
Generalagree! Pin
etkid8422-Sep-09 5:55
etkid8422-Sep-09 5:55 
GeneralRe: agree! Pin
Rajesh R Subramanian22-Sep-09 6:01
professionalRajesh R Subramanian22-Sep-09 6:01 
Generaloops, my bad Pin
etkid8422-Sep-09 6:10
etkid8422-Sep-09 6:10 
AnswerRe: how to convert char * to char[100] Pin
Skippums22-Sep-09 8:57
Skippums22-Sep-09 8:57 
char *charArray = new char[100];
char (*temp)[100]((char(*)[100])charArray);
Then temp is a pointer to a char[100] array, so *temp is your array of 100 elements. The following should also work:
char (&temp)[100](*((char(*)[100])charArray));
In this case, temp is just an alias to the array, so you don't have to dereference it prior to accessing its members.

As for the reasons to do such a thing, they are many. One is if you have to create the array using a specialized memory allocation function, such as the case where you are using an external memory manager. For example, when coding for Matlab, you have to use mxAlloc to allocate ANY memory that will persist after your function is called. However, it may be more convenient in code to treat allocated memory as an array. As another example, suppose you create a template function that takes a 3D-array that you want to overload to take a 2D array. In this case, you would have to convert a TYPE[][] to a TYPE[1][][], which is a similar operation. For example,

template<size_t height, size_t width>
void doSomething(double (&darray)[height][width]) {
    ...
}

int main() {
    const size_t height = 100;
    const size_t width  = 100;
    // The following line will NOT compile, but is used only for illustrative purposes
    double* memBlock2D = mxAlloc(height * width * sizeof(double));
    double (&memArray2D)[height][width](*((double(*)[height][width])memBlock2D));
    doSomething(memArray2D);
    return 0;
}
Hope this helps,

Sounds like somebody's got a case of the Mondays

-Jeff

modified on Tuesday, September 22, 2009 3:21 PM

QuestionHow to get cureent url from firefox address bar... Pin
onlyjaypatel22-Sep-09 3:35
onlyjaypatel22-Sep-09 3:35 
Questionaccess to the task manager Pin
einstein.girl22-Sep-09 3:27
einstein.girl22-Sep-09 3:27 
QuestionRe: access to the task manager Pin
David Crow22-Sep-09 3:34
David Crow22-Sep-09 3:34 
AnswerRe: access to the task manager Pin
kilt24-Sep-09 7:10
kilt24-Sep-09 7:10 
QuestionSleep Pin
VVVimal22-Sep-09 3:24
VVVimal22-Sep-09 3:24 
QuestionRe: Sleep Pin
David Crow22-Sep-09 3:35
David Crow22-Sep-09 3:35 
AnswerRe: Sleep Pin
VVVimal22-Sep-09 4:12
VVVimal22-Sep-09 4:12 
GeneralRe: Sleep Pin
David Crow22-Sep-09 4:13
David Crow22-Sep-09 4:13 
GeneralRe: Sleep Pin
Maximilien22-Sep-09 4:40
Maximilien22-Sep-09 4:40 
AnswerRe: Sleep Pin
Rajesh R Subramanian22-Sep-09 4:28
professionalRajesh R Subramanian22-Sep-09 4:28 
GeneralRe: Sleep Pin
etkid8422-Sep-09 6:15
etkid8422-Sep-09 6:15 
GeneralRe: Sleep Pin
Rajesh R Subramanian22-Sep-09 6:20
professionalRajesh R Subramanian22-Sep-09 6:20 
AnswerRe: Sleep Pin
etkid8422-Sep-09 6:24
etkid8422-Sep-09 6:24 
AnswerRe: Sleep Pin
Chuck O'Toole22-Sep-09 15:26
Chuck O'Toole22-Sep-09 15:26 
AnswerRe: Sleep Pin
chandu00422-Sep-09 21:01
chandu00422-Sep-09 21:01 
GeneralRe: Sleep Pin
VVVimal30-Sep-09 2:05
VVVimal30-Sep-09 2:05 
GeneralRe: Sleep Pin
Chuck O'Toole30-Sep-09 8:58
Chuck O'Toole30-Sep-09 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.