Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Setting Array SIZE....help!

Setting Array SIZE....help!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncsharpdata-structurestutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    colormyiris
    wrote on last edited by
    #1

    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 ...

    A L M 3 Replies Last reply
    0
    • C colormyiris

      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 ...

      A Offline
      A Offline
      Abin
      wrote on last edited by
      #2

      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 and delete 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.

      S 1 Reply Last reply
      0
      • C colormyiris

        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 ...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You need to create dynamic arrays on the heap using new and delete the memory yourself using delete []. unsinged long *data = new unsigned long[arraysize]; // .. working with the array delete[] data; An alternative would be a std::vector. regards

        1 Reply Last reply
        0
        • C colormyiris

          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 ...

          M Offline
          M Offline
          Mira
          wrote on last edited by
          #4

          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 allocated delete 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

          1 Reply Last reply
          0
          • A Abin

            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 and delete 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.

            S Offline
            S Offline
            Simon W 0
            wrote on last edited by
            #5

            I can't agree with you more! I am seeking... For what? Why did you ask me for what? I don't know!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups