/* Filename: files.c */ // // #include #include #include #include #include #include main() { int location = 0, found = 0, i = 0, key; int data_array[10500]; float x, y, z; x = clock(); ifstream data_file; ofstream out_file; data_file.open("numbers.dat"); if (!data_file){ cerr << "could not open file\n"; perror(""); exit(1);} cout << "Enter an integer to be located: "; cin >> key; while (i <= 10500 && found != 1) { data_file >> data_array[i]; if (key == data_array[i]) { found = 1; location = i; } else ++i; } if (found) cout << key << " is in index location " << location << endl; else cout << key << " is not in the array." << endl; y = clock(); z = (y - x)/CLOCKS_PER_SEC; //for (i = 0; i < 10; ++i) // data_file >> data_array[i]; //out_file.open("out.dat"); //while (k < 10) //{ total += data_array[k]; // out_file << data_array[k] << " "; // ++k; //} //cout << "The Total is: " << total << endl; //out_file << total; data_file.close(); printf("The execution time is: %.15f\n\n", z); //out_file.close(); return(0); }