CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    May 2008
    Posts
    7

    help in sorting array...

    hey guys,

    i am doin this program for sorting two dimnsional aray in ascendin order, and it should accpt N inputs from user... whr N is 7

    this is what i have done so far....


    now problem is it runs smoothly if u enter input with upto 6 characters, if u enter more than that, it crashes....

    please guys reply me back ASAP...
    Last edited by jdesai18; May 12th, 2008 at 09:19 AM. Reason: no help

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: help in sorting array...

    Please use a std::vector< std::vector< std::string > > instead of the old school arrays.
    If you use vectors you don't need all those strcpy statements and you don't need to worry about the size of strings. Your code is probably not allocating enough memory in your array and that's why it's crashing.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    May 2008
    Posts
    7

    Re: help in sorting array...

    thanx for reply, but this question says that i hav to use old school techniques, so i cant use vectors, n question also says that i have to use 2 for loops and 1 if statement...

    please help me....

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: help in sorting array...

    You'll have to post more since we don't see how you are allocating your array and please use the code tags when posting code!
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    May 2008
    Posts
    7

    Re: help in sorting array...

    i can send you an email, coz this is my assignment and i have done very hard work on this...

    i dont want someone to find it and copy it....

    please there''s only 2 days left....

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: help in sorting array...

    Please keep the discussion on the forum.

    You don't have to post everything, but at least start by showing us how you are allocating your array.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: help in sorting array...

    I still have no idea how you are populating your array, but since N=7, that's probably your problem. Increase it and see what happens.

    Again, in real life you will never do this like this, but just use a vector.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  8. #8
    Join Date
    May 2008
    Posts
    7

    Re: help in sorting array...

    i cannot increase that value, because i have to take 7 exact inputs.... any idea?

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: help in sorting array...

    Quote Originally Posted by jdesai18
    i cannot increase that value, because i have to take 7 exact inputs.... any idea?
    Yes, here is an idea...

    Post the whole program so that we can see exactly what you're doing. There is no way we can tell you what you're doing wrong without having a program that shows everything. Otherwise we can keep guessing forever...

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    May 2008
    Posts
    7

    Re: help in sorting array...

    but before i do this, can we delete this post instantly afterwards... ? thanks

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: help in sorting array...

    Quote Originally Posted by jdesai18
    but before i do this, can we delete this post instantly afterwards... ? thanks
    Then the entire thread loses its meaning with an erased post.

    If you have a problem with a running program, then it's up to you to debug it if you can't post something that we can also run. The issue is that your program crashes, and that crash can be caused by anything -- things we here won't know because we don't have your code.

    So we can keep guessing, or you can use your debugger to find the problem.

    Having said that, what have you done to find the problem yourself? Have you just written the code, ran it, and asking us to find the error with no effort on your part? Where are your attempts of debugging the code? Have you, at the very least, used output statements to see what the value of certain variables are (if you can't use the debugger)?

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Apr 2008
    Posts
    725

    Re: help in sorting array...

    you've probably got the array row / columns mixed up when reading the names.

    please use code tags. [ code] [/ code] (without spaces between [ or ]).

  13. #13
    Join Date
    May 2008
    Posts
    7

    Re: help in sorting array...

    so now what should i do?

  14. #14
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: help in sorting array...

    Well, for one thing it's bad form to use a global variable name as a function parameter.

  15. #15
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Re: help in sorting array...

    Quote Originally Posted by jdesai18
    i can send you an email, coz this is my assignment and i have done very hard work on this...

    i dont want someone to find it and copy it....

    please there''s only 2 days left....
    Why? This is obviously a homework assignment and not some top secret or propietary project that you are working on. I find it amusing when someone posts a question about a homework assignment that they have to do and then start demanding that people help them ASAP. After all, it's your assignment not ours.

    By the way, in your original post you never posted any code even though you said you did. Either that or you edited it and erased it after the fact. Gonna have to give this thread a "1 star rating". Even if someone was able to help you, erasing the code after the fact would make the thread unuseable for anyone else to learn from.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured