int main (int argc, char *argv){ int values[] = {1,2,3,4,5,6,7,8,9,10}; lnode *head = (lnode *) malloc(sizeof(lnode)); makeLL(&head,values); printLL(&head); insertLL(&head,23,4); printf("after inserting \n"); printLL(&head); deleteLL(&head,4); printf("after deleting \n"); printLL(&head); return 0; }
int main(int argc, char *argv[]){ temperature_List = makeLL(); int i,a; sensor_struct *data; //to run --> ./nameofMain #sensors #cycles if(argc != 3){ puts("ERROR! Format should be: ./sensor #ofSensors #ofCycles\n"); exit(0); } numSensors = atoi(argv[1]); numCycles = atoi(argv[2]); printf("Running %d cycle(s) on %d sensor(s)\n\n", numCycles,numSensors); pthread_t sensors[numSensors]; pthread_mutex_init(&locker, NULL); //fills, prints, and gets average of LL a user specified number of times for(a=1; a<=numCycles; a++){ printf("CYCLE %d:\n", a); for(i=1; i<=numSensors; i++){ data = (sensor_struct*)malloc(sizeof(sensor_struct)); data->id = i; lTime = time(NULL); sTime = (unsigned) lTime/2; data->seed = sTime; //creates new sensor thread in array --> inserts newly generated temperature if(pthread_create(&(sensors[i]), NULL, (void *)sensor, data) != 0){ perror("pthread_create"); exit(1); } } sleep(1); traverse(temperature_List); average(temperature_List); eraseList(temperature_List); } //waiting for all sensor threads to terminate for(i=1; i<=numSensors; i++){ pthread_join(sensors[i], NULL); } printf("All done. Goodbye\n"); return 0; }