Click here to Skip to main content
15,915,324 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to calculate an array's length? Pin
Peter, Chan3-Jul-07 0:08
Peter, Chan3-Jul-07 0:08 
AnswerRe: how to calculate an array's length? Pin
khan++3-Jul-07 0:25
khan++3-Jul-07 0:25 
GeneralRe: how to calculate an array's length? Pin
Peter, Chan3-Jul-07 0:36
Peter, Chan3-Jul-07 0:36 
GeneralRe: how to calculate an array's length? Pin
baerten3-Jul-07 0:48
baerten3-Jul-07 0:48 
GeneralRe: how to calculate an array's length? Pin
khan++3-Jul-07 0:48
khan++3-Jul-07 0:48 
GeneralRe: how to calculate an array's length? Pin
CPallini3-Jul-07 0:59
mveCPallini3-Jul-07 0:59 
AnswerRe: how to calculate an array's length? Pin
_AnsHUMAN_ 3-Jul-07 0:28
_AnsHUMAN_ 3-Jul-07 0:28 
AnswerRe: how to calculate an array's length? Pin
Bram van Kampen3-Jul-07 15:23
Bram van Kampen3-Jul-07 15:23 
It depends on what you want. If the array is dynamically declared, i.e. You used 'malloc', there is no knowing, unless if you build in your own scheme of determining these things. At any rate, the size of the array is known to you, because you had to give the size to the malloc function. In these cases, you need to devine a scheme to pass this knowledge on to where it is needed.

in statically declared arrays, you can use the sizeof() operator to get the size of an array in bytes. But, still again, beware and look at the language definition.

i.e.:

char * Arr[]={"First Item","Second Item"};

This is an array of pointers to character strings. Arr contains two 4-Bit Items ( or 2 8-Bit items in a 64 bit Compiler), namely the Addresses of the two strings, "First Item" and "Second Item". So in the above example,
sizeof(ARR) would always give 8 ( or 16 in a 64 bit Compiler environment). If you need to know wat's needed to store the structure ans it's data, you need:-

size_t GetTotalDataSize(){
size_t NrOfItems= sizeof(Arr)/sizeof(char*);
size_t TotalSize=sizeof(Arr);
for(int i=0;i<NrOfItems;i++)TotalSize+=(strlen(Arr+i)+1);
return TotalSize;
}



LateNightsInNewry
GeneralRe: how to calculate an array's length? Pin
Peter, Chan3-Jul-07 15:54
Peter, Chan3-Jul-07 15:54 
GeneralRe: how to calculate an array's length? Pin
Hans Dietrich4-Jul-07 1:38
mentorHans Dietrich4-Jul-07 1:38 
QuestionUsing SetWindowRgn on bitmap buttons Pin
mcsherry2-Jul-07 23:52
mcsherry2-Jul-07 23:52 
AnswerRe: Using SetWindowRgn on bitmap buttons Pin
khan++3-Jul-07 0:33
khan++3-Jul-07 0:33 
GeneralRe: Using SetWindowRgn on bitmap buttons Pin
mcsherry3-Jul-07 2:48
mcsherry3-Jul-07 2:48 
QuestionGetting SACL & Privilege Problem Pin
Akin Ocal2-Jul-07 23:44
Akin Ocal2-Jul-07 23:44 
QuestionCleaning up a struct Pin
Programm3r2-Jul-07 23:37
Programm3r2-Jul-07 23:37 
AnswerRe: Cleaning up a struct Pin
MANISH RASTOGI2-Jul-07 23:46
MANISH RASTOGI2-Jul-07 23:46 
QuestionRe: Cleaning up a struct Pin
Programm3r2-Jul-07 23:51
Programm3r2-Jul-07 23:51 
AnswerRe: Cleaning up a struct Pin
MANISH RASTOGI3-Jul-07 0:55
MANISH RASTOGI3-Jul-07 0:55 
GeneralRe: Cleaning up a struct Pin
Programm3r3-Jul-07 0:58
Programm3r3-Jul-07 0:58 
AnswerRe: Cleaning up a struct Pin
Hans Dietrich3-Jul-07 0:12
mentorHans Dietrich3-Jul-07 0:12 
GeneralRe: Cleaning up a struct Pin
Programm3r3-Jul-07 0:13
Programm3r3-Jul-07 0:13 
QuestionIs it possible to modify the systray clock menu? Pin
mid=57412-Jul-07 23:33
mid=57412-Jul-07 23:33 
AnswerRe: Is it possible to modify the systray clock menu? Pin
Perspx3-Jul-07 6:49
Perspx3-Jul-07 6:49 
QuestionRe: Is it possible to modify the systray clock menu? [modified] Pin
mid=57413-Jul-07 15:54
mid=57413-Jul-07 15:54 
AnswerRe: Is it possible to modify the systray clock menu? Pin
Perspx4-Jul-07 6:49
Perspx4-Jul-07 6:49 

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.