GROUP BY clause functionality in a C Program

Hi All,

How can I obtain a GROUP BY functionality from a C program on a File....

suppose the file is like this...

Quantity Fruit

20 Mango
30 Mango
80 Banana
200 Apple
90 Banana
100 Mango

Now I wish to run the program on this file and obtain the output as

150 Mango
170 Banana
200 Apple

In short, I have summed the quantities of each fruit

There is no group by in C. If this isn't homework, then a simple awk solution will do:

awk '{ if( $2 in array)
       {
           array[$2]+=$1;
       }
       else
       {
           array[$2]=$1;          
       }
      }
     END{ for( fruit in array )
           print array[fruit], fruit 
        }
     '  fruitfilename
       

Thank you Jim...!!!