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

arrays

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structurestutorial
4 Posts 4 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.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this: int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; .... Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    J A I 3 Replies Last reply
    0
    • N NewHSKid

      Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this: int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; .... Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      try reading the MSDN for malloc and new (free and delete also :)) Papa while (TRUE) Papa.WillLove ( Bebe ) ;

      1 Reply Last reply
      0
      • N NewHSKid

        Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this: int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; .... Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

        A Offline
        A Offline
        Adam Wimsatt
        wrote on last edited by
        #3

        If you are trying to exercize the KISS principle, then just create two different arrays and use your if to determine which to use. If you want to make it dynamic, use a linked list. My code isn't buggy. Those are all fleatures.

        1 Reply Last reply
        0
        • N NewHSKid

          Hi all, got another simple/silly question. I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this: int size = 0; if(myBool == TRUE) size = 2; else size = 8; int myArray [size]; .... Can someone tell me how to do this? I thought it was possible? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

          I Offline
          I Offline
          Ian Darling
          wrote on last edited by
          #4

          try: int * myArray = new int[size]; remember to call: delete [] myArray; when you've finished with it. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

          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