Click to See Complete Forum and Search --> : help in sorting array...


jdesai18
May 12th, 2008, 06:48 AM
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...

Marc G
May 12th, 2008, 07:43 AM
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.

jdesai18
May 12th, 2008, 07:46 AM
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....

Marc G
May 12th, 2008, 07:55 AM
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!

jdesai18
May 12th, 2008, 08:01 AM
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....

Marc G
May 12th, 2008, 08:14 AM
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 G
May 12th, 2008, 08:29 AM
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.

jdesai18
May 12th, 2008, 08:34 AM
i cannot increase that value, because i have to take 7 exact inputs.... any idea?

Paul McKenzie
May 12th, 2008, 08:45 AM
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

jdesai18
May 12th, 2008, 08:46 AM
but before i do this, can we delete this post instantly afterwards... ? thanks

Paul McKenzie
May 12th, 2008, 08:57 AM
but before i do this, can we delete this post instantly afterwards... ? thanksThen 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

Amleto
May 12th, 2008, 09:26 AM
you've probably got the array row / columns mixed up when reading the names.

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

jdesai18
May 12th, 2008, 09:29 AM
so now what should i do?

Lindley
May 12th, 2008, 09:55 AM
Well, for one thing it's bad form to use a global variable name as a function parameter.

kempofighter
May 12th, 2008, 02:39 PM
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. :mad:

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.

jdesai18
May 12th, 2008, 09:08 PM
thank u everybody for their replies... i finally figured it out....