Don't get what's wrong with my sorting array here, but the output shows that nothing was sorted.?
-
include <fstream> #include <iostream> #include <cstring> using namespace std; const int BUF_MAX = 1000; void nullArray(char*, int); void sortArray(char **arr, int max); void arrSwap(char arr1[], char arr2[]); int main() { ifstream fin; //file input int lineCount = 0; char buffer[BUF_MAX]; char **multiplier; int lineLength = 10; char **theLines = new char*[lineLength]; //Open input file: cout << "Enter a file path:\n\t==> "; cin.getline(buffer, BUF_MAX); fin.open(buffer); //Check if open failed: if(fin.fail()) { cout << "File open failed. Exiting:\n"; return 1; } //Loop until end of file: int len = 0; while(!fin.eof()) { if(len == lineLength) //If the number of values in theLines equals the size of theLines, { multiplier = theLines; lineLength *=2; theLines = new char*[lineLength]; for(int i = 0; i < len; i++) { theLines[i] = new char[strlen(multiplier[i])]; strcpy(theLines[i], multiplier[i]); } delete [] multiplier; } fin.getline(buffer, BUF_MAX); theLines[len] = new char[strlen(buffer)]; strcpy(theLines[len], buffer); nullArray(buffer, BUF_MAX); len++; } sortArray(theLines, len); fin.close(); return 0; } void nullArray(char *arr, int max) { for(int i = 0; i < max; i++) *(arr + i) = '\0'; } void sortArray(char **arr, int max) { for(int i = 0; i < strlen(arr[i]); i++) { int minimum = i; for (int j = i; j < strlen(arr[i]); j++) if (arr[j] < arr[minimum]) minimum = j; if (i != minimum) arrSwap(arr[i], arr[minimum]); } for(int i = 0; i < max; i++) cout << "length: " << strlen(arr[i]) << "\tstring: " << arr[i] << endl; } void arrSwap(char * arr1, char * arr2) { int len; int comp1 = strlen(arr1); int comp2 = strlen(arr2); if(comp1 > comp2) len = comp1; else len = comp2; char *temp = new char[len]; for (int i = 0; i < comp2; i++) temp[i] = arr2[i]; temp[comp2] = 0; for (int i = 0; i < comp1; i++) arr2[i] = arr1[i]; arr2[comp1] = 0; for (int i = 0; i < comp2; i++) arr1[i] = temp[i]; arr1[comp2] = 0; delete [] temp; } Enter a file path: ==> C:\Users\jc4gavjc\Downloads\DynArrayData… length: 22 string: Life Cycle of Software length: 0 string: length: 22 string: Phase 1: Specification length: 44 string: * Clearly specify all aspects of the problem length: 65 string: * Optional: Produce a Prototype Program that simulates a solution length: 0 string: length: 15 string: Phase 2: Design length: 21 string: * Divide into Modules length: 38 string: * Loosely Coupled, Cohesive modularity length: 20 string: * Develop Interfaces length: 46 string: * Parameters, PreConditions and PostConditions length: 0 string: length: 22 string: Phase 3: Risk Analysis length: 65 string: * Identify, Assess and Manage "risks" associated with th e project length: 0 string: length: 21 string: Phase 4: Verification length: 56 string: * Goal: Prove that your solution or algorithm is correct length: 68 string: * Assertions: Statement about a particular condition in an algorithm length: 52 string: * Identify Invariants: Condition that is always true length: 30 string: * Usually: "Prove" informally length: 0 string: length: 15 string: Phase 5: Coding length: 24 string: * Bottom-Up vs. Top-Down length: 0 string: length: 16 string: Phase 6: Testing length: 34 string: * Verify assertions and invariants length: 18 string: * Validate modules length: 0 string: length: 30 string: Phase 7: Refining the Solution length: 12 string: * Efficiency length: 9 string: * Clarity length: 12 string: * Generality length: 0 string: length: 19 string: Phase 8: Production length: 30 string: * Distribute to intended users length: 9 string: * Archive length: 0 string: length: 20 string: Phase 9: Maintenance length: 12 string: * Fix errors length: 18 string: * Enhance features length: 0 string: length: 37 string: For most "larger" software projects, length: 47 string: --> Phases 1-8 comprise 30% of the overall work length: 40 string: --> Phase 9 (Maintenance) comprises 70%. length: 0 string: Press any key to continue . . .
-
Answer:
www.csforless.tk
writetom... at Yahoo! Answers Visit the source
Related Q & A:
- Feeling sick, but I don't know what it's from?Best solution by Yahoo! Answers
- What is a post car ? I see that on a muscle car ad and I just don't get it?Best solution by Yahoo! Answers
- What do you do if you pay for something online, and you don't get it?Best solution by Yahoo! Answers
- What happens if you don't get into medical school?Best solution by studentdoctor.net
- Comcast internet & internet TV don't get along?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.