| | |
select sort using array of pointers---getting wrong values.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 4
Reputation:
Solved Threads: 0
Hi all,
I was writing a program for sorting the test scores using array of pointers and dynamic memory allocation. Surprisingly, I am getting indefinite values after sorting. I wrote a header file, .cpp file and main. cpp.
Actually, after sorting I thought of adding an average function in .cpp file and can call that function in main.
But first of all, I am unable to sort the test scores properly.
Can anybody tell me where I went wrong?
I am sending my code as attachment.
Thanks in advance.
I was writing a program for sorting the test scores using array of pointers and dynamic memory allocation. Surprisingly, I am getting indefinite values after sorting. I wrote a header file, .cpp file and main. cpp.
Actually, after sorting I thought of adding an average function in .cpp file and can call that function in main.
But first of all, I am unable to sort the test scores properly.
Can anybody tell me where I went wrong?
I am sending my code as attachment.
Thanks in advance.
your program will not even compile correctly so why are you trying to run it. arrays can not be allocated the way you are attempting in line 4 below. You need to make variable tests a pointer and use new to allocate the memory after line 6, at which time the value of numScores will be known.
c Syntax (Toggle Plain Text)
int main() { int numScores; int tests[numScores]; cout << "Enter the number of test scores:"; cin >> numScores;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Apr 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
your program will not even compile correctly so why are you trying to run it. arrays can not be allocated the way you are attempting in line 4 below. You need to make variable tests a pointer and use new to allocate the memory after line 6, at which time the value of numScores will be known.
c Syntax (Toggle Plain Text)
int main() { int numScores; int tests[numScores]; cout << "Enter the number of test scores:"; cin >> numScores;
Can anyone please resolve this.
![]() |
Similar Threads
- Passing 2D Array of Pointers into a function (C++)
- Sort A Multidimension Array (Python)
- Sort multidimensional array on more than one column? (ASP)
- Array of pointers to objects (C++)
- How to Sort a MultiDimensional Array (C)
- Array of pointers (C++)
Other Threads in the C++ Forum
- Previous Thread: Help!
- Next Thread: Solutions and Projects
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






