Click here to Skip to main content
15,892,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: best way to replace items in a string Pin
dazinith19-Mar-02 11:00
dazinith19-Mar-02 11:00 
GeneralRe: best way to replace items in a string Pin
Joaquín M López Muñoz19-Mar-02 11:50
Joaquín M López Muñoz19-Mar-02 11:50 
QuestionSuggestions on Using Grids? Pin
dazinith19-Mar-02 9:08
dazinith19-Mar-02 9:08 
AnswerRe: Suggestions on Using Grids? Pin
Tomasz Sowinski19-Mar-02 9:19
Tomasz Sowinski19-Mar-02 9:19 
AnswerRe: Suggestions on Using Grids? Pin
alex.barylski19-Mar-02 9:52
alex.barylski19-Mar-02 9:52 
GeneralRe: Suggestions on Using Grids? Pin
dazinith19-Mar-02 10:31
dazinith19-Mar-02 10:31 
QuestionDynamic array??? Possible??? Pin
19-Mar-02 8:25
suss19-Mar-02 8:25 
AnswerRe: Dynamic array??? Possible??? Pin
Paul M Watt19-Mar-02 8:42
mentorPaul M Watt19-Mar-02 8:42 
No, that is because creating an array with int arrayvalue[size] allocates space for your array on the stack, and that requires the compiler to know how large the buffer is. Which means that size cannot be a dynamic value.

In order to dynamically allocate space for the array, you will need to allocate space with a pointer like this:

cin >> size;

//allocate space for your array.
int *arrayvalue = new int[size];
// it is a good idea to check the return value from a call to new.
// the return value from new is NULL of the memory allocation fails.
if (NULL == arrayvalue)
{
  // handler this error here.
}
else
{
  // use your array like you would any other array.
  arrayvalue[0] = 100;
  ...

  //free the memory for your array later with this call.
  delete[] arrayvalue;
}


One more thing, you should make sure that the value for array is not 0, because you will get a valid pointer back for an array of size zero, but if you try to access the array at all, you will be an memory access violation.
AnswerRe: Dynamic array??? Possible??? Pin
Tomasz Sowinski19-Mar-02 8:49
Tomasz Sowinski19-Mar-02 8:49 
AnswerRe: Dynamic array??? Possible??? Pin
Nemanja Trifunovic19-Mar-02 8:49
Nemanja Trifunovic19-Mar-02 8:49 
AnswerRe: Dynamic array??? Possible??? Pin
dazinith19-Mar-02 9:00
dazinith19-Mar-02 9:00 
GeneralRe: Dynamic array??? Possible??? Pin
Christian Graus19-Mar-02 10:22
protectorChristian Graus19-Mar-02 10:22 
QuestionHow to create global variable? Pin
19-Mar-02 7:49
suss19-Mar-02 7:49 
AnswerRe: How to create global variable? Pin
Carlos Antollini19-Mar-02 7:51
Carlos Antollini19-Mar-02 7:51 
AnswerRe: How to create global variable? Pin
Paul M Watt19-Mar-02 8:07
mentorPaul M Watt19-Mar-02 8:07 
GeneralRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 8:11
Tomasz Sowinski19-Mar-02 8:11 
GeneralRe: How to create global variable? Pin
Paul M Watt19-Mar-02 8:21
mentorPaul M Watt19-Mar-02 8:21 
GeneralRe: How to create global variable? Pin
Christian Graus19-Mar-02 10:24
protectorChristian Graus19-Mar-02 10:24 
GeneralRe: How to create global variable? Pin
Paul M Watt19-Mar-02 10:34
mentorPaul M Watt19-Mar-02 10:34 
GeneralRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 10:43
Tomasz Sowinski19-Mar-02 10:43 
GeneralRe: How to create global variable? Pin
Christian Graus20-Mar-02 0:31
protectorChristian Graus20-Mar-02 0:31 
GeneralRe: How to create global variable? Pin
Bill Wilson19-Mar-02 14:03
Bill Wilson19-Mar-02 14:03 
GeneralRe: How to create global variable? Pin
Bill Wilson19-Mar-02 14:03
Bill Wilson19-Mar-02 14:03 
AnswerRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 8:10
Tomasz Sowinski19-Mar-02 8:10 
GeneralSame caption problem as before, what am I doing wrong? (half reposted) Pin
generic_user_id19-Mar-02 7:48
generic_user_id19-Mar-02 7:48 

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.