Sorting a file with names

Hey guys what im trying to accomplish is to sort an array of names and scores from a file with the first line being a number of how many names and scores follow. In my program when i find the number at the top i.e 4 or 5 when i output a file with the names sorted in ascending or descending order it sorts the scores correct but it only shows the name at the location of the number that was at the very top of the file. Ive tried to figure it out but i cant so i wanted to see what yall thought. heres the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

void main(int argc, char *argv[])
{
  //char * names [] = {"Joe", "Bob", "Sally", "Brenda", "Sam"};
  //unsigned int scores[] = {95, 100, 88, 66, 90};
  
  char name[80];
  unsigned int score;
  int lineIndex = 0;
  char line[80];
  cin.getline (line, 80);
  unsigned int count = atoi(&line[lineIndex]);
  char * names [100];
  unsigned int scores [100];
  unsigned int sizeOfData;
  
  
  //sizeOfData = getNumDataItemsFromCIN ();
  //allocateArrayOfNamePointers (sizeOfData); //allocate memory for array of names
  //allocateArrayOfScores (sizeOfData);
  //cout <<" sizeOfData   hello is  "<<sizeOfData<<endl;
  
  for (int index = 0; index < count; index++)
  {
     bool readLineOK = readAndParseDataLineFromCIN (name, score);
     HERES WHERE I THINK THE PROBLEM IS.
if (readLineOK)
     {
	   //sortNameAndScoreArrays (names, scores, count, SORT_BY_NAME, ASCENDING_ORDER);
       
		//@#$@%#$^%#%^$&^%*$^&# code 
		names[index] = name;
	   scores[index] = score;
	   //cout << name << endl;
       //cout << score << endl << endl;
	   
     }
     else cout << "Error reading line " << index + 1 << endl << endl;

  }

  if(string(argv[1]) == "name" && string(argv[2]) == "asc"){
	cout << "ascending names" << endl;
	sortNameAndScoreArrays (names, scores, count, SORT_BY_NAME, ASCENDING_ORDER);
	sendResultsToOutput (names, scores, count); 
  }
  else if(string(argv[1]) == "score" && string(argv[2]) == "asc"){
	cout << "ascending score" << endl;  
	sortNameAndScoreArrays (names, scores, count, SORT_BY_SCORE, ASCENDING_ORDER);
	sendResultsToOutput (names, scores, count); 
  }
  else if(string(argv[1]) == "score" && string(argv[2]) == "des"){
	cout << "descending score" << endl;
	sortNameAndScoreArrays (names, scores, count, SORT_BY_SCORE, DESCENDING_ORDER);
		sendResultsToOutput (names, scores, count); 
  }
  else if(string(argv[1]) == "name" && string(argv[2]) == "des"){
	cout << "names descending" <<  endl;
	sortNameAndScoreArrays (names, scores, count, SORT_BY_NAME, DESCENDING_ORDER); 
	sendResultsToOutput (names, scores, count); 
  }


Can you please give an example input and how it should be sorted? It's really hard to read through all that code and I'm not even sure I get what exactly you are trying to do.
Topic archived. No new replies allowed.