int main (int argc, char** argv) { struct arrayBagStack *a = (struct arrayBagStack *)malloc(sizeof(struct arrayBagStack)); initArray(a); printf("Is stack array empty? %i\n", isEmptyArray(a)); printf("Add 3, 2, 7, 14 & 9 to the stack, using bag.\n"); addArray(a, 3); addArray(a, 2); addArray(a, 7); addArray(a, 14); addArray(a, 9); printf("the number at the top of the array is: %i\n", topArray(a)); printf("How many numbers are now in the array? %i\n", sizeArray(a)); printf("Remove last 2 values from the array, using stack implementation.\n"); popArray(a); popArray(a); printf("How many numbers are now in the array? %i\n", sizeArray(a)); printf("The number at the top of the array is now: %i", topArray(a)); printf("\n"); return 0; }
int main(){ int size = 8*128; int flash[size]; popArray(flash,size); //new flash update(flash,size); //write new block 0 //not exactly sure what this does, but it's necessary // erase(flash,1,24,size,"poo"); return 0; }
void *threadTask(void *tid ) { int i, start, *mytid, end ; long int mysum=0; long int sumVal=0; /* A LOCAL VARIABLE TO STORE CUBE VALUE */ /* PROCESS SECTION OF THE LARGE ARRAY . WE ARE INTERESTED IN PART OF ARRAY ASSIGNED TO THIS THREAD ONLY */ mytid = (int *) tid; start = (*mytid * SEGMENTS); end = start + SEGMENTS; FILE *fptr; char fname[100]; printf ("New thread ID : %d created. It will process array members : AR[ %d ] to AR[ %d ].\n",*mytid,start,end-1); popArray(start, end); // WE WRITE OUTPUTS TO A FILE snprintf (fname, sizeof(fname), "Processed_by_thread_%d.txt",*mytid); // print thread id into filename pthread_mutex_lock (&add_mutex); fptr=fopen(fname,"w"); if(fptr==NULL){ printf("Error!"); exit(1); } for (i=start; i < end ; i++) { sumVal = (AR[i] + AR[i]) ; /* CALCULATE THE SUM OF A MEMBER WITH ITSELF AND STORE IN LOCAL VARIABLE */ fprintf(fptr,"Sum of %d + %d = %d \n", AR[i], AR[i], sumVal); } printf ("Thread ID %d completed its job! Output saved to file : Processed_by_thread_%d.txt \n",*mytid, *mytid); /* Lock the mutex and update the global sum, then exit */ fclose(fptr); pthread_mutex_unlock (&add_mutex); pthread_exit(NULL); }