main() { FILE *in; int rtn,i; in = fopen ("/Users/laurenceschenk/mini-src/mySrc/Coldipozzo/type_1_sort","r"); if (in == NULL) { perror ("Unable to open type_1_sort\n"); exit (1); } rtn = shared_memory_attach(); clear_shm(); while (1) { rtn = fscanf(in,"%d\t%s\t%s\t%d",&etime,name,days,&action); if (rtn == EOF) break; printf ("Data read: name %s time %d days %s action %d\n",name,etime,days,action); //write_to_shm(); rtn = get_name_index(name); if (( rtn > -1) && (rtn < NUM_DEVICES)) { write_to_shm(rtn); } else { printf ("**********FAILURE to find %s\n",name); printf ("\n\n*****************program abort....\n"); shared_memory_detach(); exit(5); } } fclose(in); shared_memory_detach(); printf("shm_type_1:main written %d records\n",ptr); exit(0); }
int main() { vector<string> names; vector<int> scores; string name; int score; // read input cout << "Please enter set of names and scores: i.e. John 17 Jane 1 etc\n"; cout << "Enter 'NoName 0' to stop input\n"; bool stop_input = false; while (!stop_input){ // read input data cin >> name >> score; if (is_stop_input(name, score)) { stop_input = true; } else { // terminate if nonunique name was provided if (!is_name_unique(name, names)) { simple_error("Name entered is not unique: " + name + ". Please provide unique names"); } // store input in containers names.push_back(name); scores.push_back(score); output_successful_input(name, score); } } // write pairs name - score output_names_and_scores(names, scores); // ask user for names and print scores for the names cout << "OK, now give me the name - and I'll show you the score for it\n"; int index; while (cin >> name) { index = get_name_index(name, names); if (-1 != index) { cout << "(" << name << "," << scores[index] << ")\n"; } else { cout << "Name " << name << " not found!\n"; } } }