Thread: Grouping

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by adak View Post
    so is that persons matrix number bk08110110 or is it just 08110110?

    bk08110110

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    OK, so if (strcmp(string1, string2) == 0) or equals > 0 (first string is greater than the 2nd one, or equals < 0, (second string is greater than the first string).

    Sure, but can you put that into the Sort function and make it work??

    Give it a try. I'll check back in a bit.

  3. #18
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    After #include

    Code:
    void Sorter(void);
    inside main(), after calculation

    Code:
    Sorter();


    outside main()

    Code:
    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 (strcmp(ptr1->student[10], ptr2->student[10]) < 0 )  {
                strcpy(*ptrtemp, *ptr1);
                strcpy(*ptr1, *ptr2);
                strcpy(*ptr2, *ptrtemp);
              }
          }
       }
    }
    error C2440: 'function' : cannot convert from 'Record' to 'char *'


    i tried putting the

    Code:
    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 (strcmp(ptr1->student[10], ptr2->student[10]) < 0 )  {
                strcpy(*ptrtemp, *ptr1);
                strcpy(*ptr1, *ptr2);
                strcpy(*ptr2, *ptrtemp);
              }
          }
       }
    }

    inside main() after the Sorter(); but it gives tons of error
    Last edited by archriku; 03-26-2009 at 09:03 AM.

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    Code:
    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 (strcmp(ptr1->student, ptr2->student) > 0 )  {
                strcpy(*ptrtemp, *ptr1);
                strcpy(*ptr1, *ptr2);
                strcpy(*ptr2, *ptrtemp);
              }
          }
       }
    }
    error C2440: 'function' : cannot convert from 'Record' to 'char *'
    student[10] is the char in the 11th spot of the student array. You don't want that. You want just "student", which is the address of the entire char array. I fixed it, above.

    WAIT!! NO STRCPY() EITHER!! Let the pointers do their magic!!

    What a spoilsport!!
    Last edited by Adak; 03-26-2009 at 09:09 AM.

  5. #20
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    i change already but i get this error cannot convert from 'Record' to 'char *'

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    You took out the strcpy() calls? And returned the assignment operator: =

  7. #22
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    so what i have 2 do? change it back to

    v
    Code:
    oid 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;
             }
          }
       }
    }
    but change the total to student?

  8. #23
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    Yepper!

    WAIT! Now you've taken out the strcmp() !!

    We need strcmp() to compare what the two ptr->student things are, and tell us which is greater.
    Last edited by Adak; 03-26-2009 at 09:24 AM.

  9. #24
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    no more error in the compiling but i get debug error it says the variable ptrtemp is being use without initialiased

    warning C4700: uninitialized local variable 'ptrtemp' used

    so how to initialized ptrtemp?
    Last edited by archriku; 03-26-2009 at 09:44 AM.

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    I don't get any warnings, so I'm not sure.

    After the strcmp() line, you should have three lines of code for the ptrs:

    Code:
    *ptrtemp = *ptr1;
    *ptr1 = ptr2;
    *ptr2 = ptrtemp;
    Maybe you have a typo or something?

    Make sure ptrtemp is NOT mentioned in any other place except where it's declared, and here.

    We could add
    Code:
    ptrtemp = NULL;
    where it's created.
    Last edited by Adak; 03-26-2009 at 09:55 AM.

  11. #26
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by Adak View Post
    I don't get any warnings, so I'm not sure.

    After the strcmp() line, you should have three lines of code for the ptrs:

    Code:
    *ptrtemp = *ptr1;
    *ptr1 = ptr2;
    *ptr2 = ptrtemp;
    Maybe you have a typo or something?

    Make sure ptrtemp is NOT mentioned in any other place except where it's declared, and here.

    We could add
    Code:
    ptrtemp = NULL;
    where it's created.
    hey thx alot for helping=]

  12. #27
    Registered User
    Join Date
    Sep 2006
    Posts
    8,866
    You're welcome.

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