/* CSE 303, Spring 2009, Marty Stepp This program reads a file of phone numbers and prints them in sorted order. It uses a giant array of 10,000,000 boolean values as a tally; if phone number 123-4567 is seen, it sets the array element at index 1234567 to true. Then, to print the values in sorted order, it just traverses the array and prints the values that have been set to true. */ #include #include #include #include int main(void) { int i; bool* nums = (bool*) calloc(10000000, sizeof(bool)); // read phone numbers from file and tally them into bool array FILE* f = fopen("phone1m.txt", "r"); while (!feof(f)) { int phonenum; fscanf(f, "%d", &phonenum); nums[phonenum] = true; } fclose(f); // print phone numbers in sorted order for (i = 0; i < 10000000; i++) { if (nums[i]) { printf("%d\n", i); } } // pause at end of program getchar(); return 0; }