Setting Array SIZE....help!
-
Hello all . i having some question about array size. lets say i wanto declare this array...its an "unsigned long". lets say i wanted it the array to have the size of "8".. so i will declare like this : unsigned long Data[8]; ok...lets say now.. i wanto to create a "unsigned long" array.. but i not yet sure whats the size...becoz its depends on the datas that will be key in by user... ok.. lets say.. int arraysize; arraysize=a+b; (where a and b are both int keyed in by user...) then.. how i wanto set the Data array into the size of "arraysize"?? can i do it like this : unsigned long Data[arraysize]; i tired but..error... so i hope u guys can help me out..how to solve this problem...what should i do to set my array size according to wat the datas user keyed in? thanks... thong twh81@tm.net.my ...
-
Hello all . i having some question about array size. lets say i wanto declare this array...its an "unsigned long". lets say i wanted it the array to have the size of "8".. so i will declare like this : unsigned long Data[8]; ok...lets say now.. i wanto to create a "unsigned long" array.. but i not yet sure whats the size...becoz its depends on the datas that will be key in by user... ok.. lets say.. int arraysize; arraysize=a+b; (where a and b are both int keyed in by user...) then.. how i wanto set the Data array into the size of "arraysize"?? can i do it like this : unsigned long Data[arraysize]; i tired but..error... so i hope u guys can help me out..how to solve this problem...what should i do to set my array size according to wat the datas user keyed in? thanks... thong twh81@tm.net.my ...
I don't think I should give you a direct answer on your question because, frankly, doing so would not be a help to you, in the long run. I suggest you complete the C++ text book(s) you are reading first, and I guarantee you'll find the solution by yourself. As a hint, please take a look at the
new
anddelete
operators(I assume you are learning C++) about how to use dynamic arrays and how to free the memory. Really, I'm sorry for not being a one-time help but if you are developing an application, ask that question here, get a direct answer, then return to your application, I'm afraid your customer(or your teacher) will end up get mad. -
Hello all . i having some question about array size. lets say i wanto declare this array...its an "unsigned long". lets say i wanted it the array to have the size of "8".. so i will declare like this : unsigned long Data[8]; ok...lets say now.. i wanto to create a "unsigned long" array.. but i not yet sure whats the size...becoz its depends on the datas that will be key in by user... ok.. lets say.. int arraysize; arraysize=a+b; (where a and b are both int keyed in by user...) then.. how i wanto set the Data array into the size of "arraysize"?? can i do it like this : unsigned long Data[arraysize]; i tired but..error... so i hope u guys can help me out..how to solve this problem...what should i do to set my array size according to wat the datas user keyed in? thanks... thong twh81@tm.net.my ...
-
Hello all . i having some question about array size. lets say i wanto declare this array...its an "unsigned long". lets say i wanted it the array to have the size of "8".. so i will declare like this : unsigned long Data[8]; ok...lets say now.. i wanto to create a "unsigned long" array.. but i not yet sure whats the size...becoz its depends on the datas that will be key in by user... ok.. lets say.. int arraysize; arraysize=a+b; (where a and b are both int keyed in by user...) then.. how i wanto set the Data array into the size of "arraysize"?? can i do it like this : unsigned long Data[arraysize]; i tired but..error... so i hope u guys can help me out..how to solve this problem...what should i do to set my array size according to wat the datas user keyed in? thanks... thong twh81@tm.net.my ...
hi it seems that u really have not finished your C++ courses. the array that you are using is not a dynamic array. you need to know more about POINTERS. These are really the dynamic arrays. if u r in a hurry u can use these lines. but my advice is that you should read more in C++ specially in pointers and dynamic memory allocation. First you declare ur array like this:
unsigned long *Data;
when you know the actaual size of ur array you set it like this:**Data= new unsigned long[arraySize];**
now u can use it as an ordinary array. after u finish using it is better to free the memor u allocateddelete Data;
i hope this works with you but you still need to know more in C++ Good Luck. The music in my heart I bore Long after it was heard no more. - William Wordsworth -
I don't think I should give you a direct answer on your question because, frankly, doing so would not be a help to you, in the long run. I suggest you complete the C++ text book(s) you are reading first, and I guarantee you'll find the solution by yourself. As a hint, please take a look at the
new
anddelete
operators(I assume you are learning C++) about how to use dynamic arrays and how to free the memory. Really, I'm sorry for not being a one-time help but if you are developing an application, ask that question here, get a direct answer, then return to your application, I'm afraid your customer(or your teacher) will end up get mad.