Thread: Grouping

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    77

    Grouping

    No Matrix Total Grade
    1 BK20001 84 A
    2 BK20002 62 B-
    3 BK20003 75 A-
    4 BK20004 81 A
    5 BK20005 70 B+
    6 BK20006 39 D
    7 BK20007 78 A-
    8 BK20008 69 B
    9 BK20009 49 C-


    how do i group 1 BK20001 84 A together so when i sort the matrix the total and grade will follow?what code do i use to group them?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You could use the index sort I posted for you, previously.

    Stand by and I'll go back to that program, and do it another way. Have you been taught pointers yet?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    You could use the index sort I posted for you, previously.

    Stand by and I'll go back to that program, and do it another way. Have you been taught pointers yet?
    yes i have been taught but i dont really know how to use it confuse me.

    nvm u can try tell me how to point then i try find a way out of it.. if cant then i will just use another method

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Try something like this. It sorts according to totals now, but you can change it to any records.member you want.

    Code:
    void Sorter(void)   {
       int i, j;   //these are just used for counting, nothing fancy
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->total < ptr2->total)  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
             }
          }
       }
    }

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    Try something like this. It sorts according to totals now, but you can change it to any records.member you want.

    Code:
    void Sorter(void)   {
       int i, j, gar;   //these are just used for counting, nothing fancy
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->total < ptr2->total)  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
                gar++;
             }
          }
       }
    }
    i want to short by matrix number.. so i just change the part

    i
    Code:
    f(ptr1->total < ptr2->total)    {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
                gar++;
             }
    to

    i
    Code:
    f(ptr1->matrix <ptr2 ->matrix {
    strcpy(*ptrtemp, *ptr1);
    strcpy(*ptr1, *ptr2);
    strcpy(*ptr2, *ptrtemp);
    gar++;
    }

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    Try something like this. It sorts according to totals now, but you can change it to any records.member you want.

    Code:
    void Sorter(void)   {
       int i, j;   //these are just used for counting, nothing fancy
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->total < ptr2->total)  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
             }
          }
       }
    }
    do i put this under main?

    i try this fuction in main after the calculate part?i get alot error by doing so..

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I had it in it's own function called Sorter();

    You need to add the prototype for the function:
    void Sorter(void);

    Before main();

    Then you call the Sorter function with this:
    Sorter();
    in main(), after you do the calculations to get the total.

    I don't know what "matrix number" is. You can sort it according to any of these things:
    Code:
    typedef struct {
       char student[30];
       int no;
       int q1;
       int q2;
       int q3;
       int proj;
       int mid;
       int final;
       int total;
    }
    and nothing else (unless you change it).

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    i still get error ok this is what i did

    Code:
    #include<stdio.h>
    #include<string.h>
    
    void Sorter(void)
    then after the calculation part i do this.

    Code:
    sorter();
    
    void Sorter(void)   {
       int i, j;  
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->total < ptr2->total)  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
             }
          }
       }
    }
    but i still get alot of error, what i did wrong?

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You called Sorter, "sorter", and that won't fly. Change it to Sorter();

  10. #10
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    You called Sorter, "sorter", and that won't fly. Change it to Sorter();

    i still get the same error after i change it..

    after calculation


    Code:
    Sorter(void);
    
       void Sorter(void)   {
       int i, j;   
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->student[30] < ptr2->student[30])  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
             }
          }
       }
    }

    alot of the error came out as missing { or ( something like that.. i m thinking izzit the void Sorter fuction came in wrong place?
    Last edited by archriku; 03-26-2009 at 08:18 AM.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by archriku View Post
    i still get the same error after i change it..

    after calculation


    Code:
    Sorter(void);
    
       Sorter(void)   {
       int i, j;   
       Record *ptr1;
       Record *ptr2;
       Record *ptrtemp;  
    
       for(i = 0; i < 10-1; i++)  {
          for(j = i+1; j < 10; j++)  {
             ptr1 = &records[i];
             ptr2 = &records[j];
             if(ptr1->student[30] < ptr2->student[30])  {
                *ptrtemp = *ptr1;
                *ptr1 = *ptr2;
                *ptr2 = *ptrtemp;
             }
          }
       }
    }

    alot of the error came out as missing { or ( something like that.. i m thinking izzit the void Sorter fuction came in wrong place?
    void Sorter(void);

    Goes up on top (outside) of main().

    I'm really confused. What do want to sort these records by?

    First it was "total", then it was "matrix number" (whatever that is), and now you're here with "student"

    You can't compare strings in C, like that. You have to use strcmp(string1, string2) == 0, or is > 0, or is < 0, to compare strings.

  12. #12
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    void Sorter(void);

    Goes up on top (outside) of main().

    I'm really confused. What do want to sort these records by?

    First it was "total", then it was "matrix number" (whatever that is), and now you're here with "student"

    You can't compare strings in C, like that. You have to use strcmp(string1, string2) == 0, or is > 0, or is < 0, to compare strings.
    nono dont need to sort with total.. the student is actually matrix number but i just declare it as student something like that..

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So the first two letters are like the initials of the student or teacher, and the number that follows it is the students "matrix number"?

    Is that right?

  14. #14
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    So the first two letters are like the initials of the student or teacher, and the number that follows it is the students "matrix number"?

    Is that right?
    yea BK08110110 something like a person ID

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by archriku View Post
    yea BK08110110 something like a person ID
    So is that persons matrix number BK08110110 or is it just 08110110?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grouping two related lines together from a file...help!
    By cproghelp in forum C Programming
    Replies: 3
    Last Post: 12-05-2004, 04:56 PM
  2. character grouping
    By imApig in forum C Programming
    Replies: 2
    Last Post: 03-20-2003, 02:22 PM
  3. Help with grouping & ignoring pronunciation
    By zipfur in forum C Programming
    Replies: 2
    Last Post: 10-17-2002, 10:29 AM
  4. unix command for grouping....
    By kiss2rvp in forum Linux Programming
    Replies: 2
    Last Post: 05-29-2002, 09:49 AM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM