posted by Anonymous on .
Write a C program to sort the bags by weight. Assume that the input is given in
a file. Each line of the input file corresponds to one polythene bag. For example
a line in the file as below
corresponds to a bag containing four 10 paisa coins and two coins of 20 and 50
This is what I would do:
1. Open the file for reading (use fopen()) and read in the file, one line at a time. Each line will be read into a string (or character array).
2. The line will be read in one number at a time using sscanf, until no more number is available, or use the strtoken() to read them all into an array.
3. The numbers will be added up, and the sum put into an array. No index array is required if the question does not require identifying the order of the bags.
4. Sort the resulting array using a method of your choice.
5. output the resulting sorted array.
Feel free post your code for help in debugging or verification.