Thread: C programming sort of student records

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    C programming sort of student records

    So I have to read a file that contains student records in the form:

    lastname, firstname:studentid:score1:score2:score3:score4:sc ore5:grade

    and store them in an array of structures. I then have to print a menu for the user to chose what they want to do with the list of records (i.e. sort or print). Anyways, I am having trouble with my sort algorithm. It only swaps the first letter of each name and I need it to swap the whole record. I do not have to sort by last name and first name, only by the first letter of each name field in the list. Can anyone help?

    insert
    Code:
    void sortListName(STUDENT records[], int count)
    {
       int smallest;
       int tempData;
       int current;
       int walk;
        
         for (current = 0; current < count; current++)
         {
    	      smallest = current;
              for (walk = current + 1; walk <= count; walk++)
    		  {
    	     
                 if ((strcmp(records[walk].name, records[smallest].name)) < 0)
    		         smallest = walk;
    		  }
              tempData = *records[current].name;
              *records[current].name = *records[smallest].name;
              *records[smallest].name = tempData;
         }
    	 
       return;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    tempdata should be a STUDENT, not an int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 03-03-2010, 01:33 AM
  2. Linked Lists with multiple programs
    By crimsonpetal13 in forum C Programming
    Replies: 21
    Last Post: 02-22-2010, 10:56 PM
  3. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  4. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 08:05 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM