Thread: Array manipulation Question

  1. #16
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    ok so it works now except one thing.....

    The array before sorting: 4 3 2 1
    The array after sorting: -708361232 1 2 3

    trying to figure it out.... can anyone else spot it?

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    they said C++.....

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    They were wrong. VLAs are in C99 or a GCC-specific extension, but not C++.

    Looks like an out-of-bounds memory access, and off-by-one error.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    well if it is c99 why is it working?.... ya i assumed it was an out of bounds.... just struggling to find it....

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    well if it is c99 why is it working?
    It is a g++ extension ported from gcc's support for C99. You can disable it with the -pedantic option (and/or -ansi, I am not too sure).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    well figured out the out of bounds error..... but the algorithm doesn't seem to work.... so gotta go figure that out :-P

    thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Create Array size Question
    By popohoma in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 03:04 AM