int c_main( void ) { UBreakIterator *boundary; char cStringToExamine[] = "Aaa bbb ccc. Ddd eee fff."; UChar stringToExamine[sizeof(cStringToExamine)+1]; UErrorCode status = U_ZERO_ERROR; printf("\n\n" "C Boundary Analysis\n" "-------------------\n\n"); printf("Examining: %s\n", cStringToExamine); u_uastrcpy(stringToExamine, cStringToExamine); /*print each sentence in forward and reverse order*/ boundary = ubrk_open(UBRK_SENTENCE, "en_us", stringToExamine, -1, &status); if (U_FAILURE(status)) { printf("ubrk_open error: %s\n", u_errorName(status)); exit(1); } printf("\n----- Sentence Boundaries, forward: -----------\n"); printEachForward(boundary, stringToExamine); printf("\n----- Sentence Boundaries, backward: ----------\n"); printEachBackward(boundary, stringToExamine); ubrk_close(boundary); /*print each word in order*/ boundary = ubrk_open(UBRK_WORD, "en_us", stringToExamine, u_strlen(stringToExamine), &status); printf("\n----- Word Boundaries, forward: -----------\n"); printEachForward(boundary, stringToExamine); printf("\n----- Word Boundaries, backward: ----------\n"); printEachBackward(boundary, stringToExamine); /*print first element*/ printf("\n----- first: -------------\n"); printFirst(boundary, stringToExamine); /*print last element*/ printf("\n----- last: --------------\n"); printLast(boundary, stringToExamine); /*print word at charpos 10 */ printf("\n----- at pos 10: ---------\n"); printAt(boundary, 10 , stringToExamine); ubrk_close(boundary); printf("\nEnd of C boundary analysis\n"); return 0; }
int main(int argc, char* argv[]){ FILE *ifp; ifp = fopen(argv[1], "r"); char input[10]; // array to store line char cmd; char *cmdPtr; int element = 1; circularQueue q; while (fgets(input, 10, ifp)){ cmdPtr = strtok(input, " "); cmd = cmdPtr[0]; if (cmd == 'n' || cmd == 'e') element = atoi(strtok(NULL, " ")); switch(cmd){ case 'e': enqueue(q, element); break; case 'd': dequeue(q); break; case 'f': printFirst(q); break; case 'r': printRear(q); break; case 'n': q = makeEmpty(element); break; case 'p': // printing off the array to test if circular array is working for(int i=0; i<q->max_queue_size; i++) printf("[%i],", q->key[i]); printf("\n"); } } deleteQueue(q); // free the memory fclose(ifp); return 0; }
int main(void){ unsigned tid = 0, i; ThreadCB* th; TList* queue1 = tlNewList(); TList* queue2 = tlNewList(); TList* prioliste1 = tlNewList(); TList* prioliste2 = tlNewList(); // show empty queues ------------------------------------------------------- beginTest(); printList(queue1, "queue1 -> empty"); printList(queue2, "queue2 -> empty"); printList(prioliste1, "prioliste1 -> empty"); printList(prioliste2, "prioliste2 -> empty"); endTest(); // add one thread to queue 2 ----------------------------------------------- beginTest(); th = mtNewThread(tid++, 1, 40); tlEnqueue(queue2, th); printList(queue2, "queue2, after one put"); // put last 5 threads ------------------------------------------------------ tlEnqueue(queue2, mtNewThread(tid++,1,20)); tlEnqueue(queue2, mtNewThread(tid++,1,30)); tlEnqueue(queue2, mtNewThread(tid++,2,35)); tlEnqueue(queue2, mtNewThread(tid++,3,50)); tlEnqueue(queue2, mtNewThread(tid++,3,10)); printFirst(queue2, "queue2 after 6 puts"); printList(queue2, "queue2 after 6 puts"); endTest(); // move threads between queues --------------------------------------------- beginTest(); printList(prioliste1, "prioliste1 -> empty"); tlSortIn(prioliste1, mtNewThread(tid++, 4,1000)); tlSortIn(prioliste1, mtNewThread(tid++, 4, 999)); for (i = 1; i <= 6; i++) { printFirst(queue2, "--->> queue2, for-loop before pop"); th = tlDequeue(queue2); if (th == NULL) printf("\t th == NULL at iteration i = %d", i); else { printList(queue2, "queue2, for-loop after pop"); tlEnqueue(queue1, th); // in andere Queue einreihen tlSortIn(prioliste1, th); // in die sort.Liste einreihen printList(prioliste1, "prioliste1, for-loop"); } } printList(queue2, "queue2, after 1. for loop"); printList(prioliste1, "prioliste1, after 1. for loop"); printList(queue1, "queue1, after 1. for loop"); endTest(); // add a lot of threds to queue 1 then pop 590 threads beginTest(); for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 5, 500+2*i)); } for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 6, 401+2*i)); } for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 7, 600+2*i)); } for (i=1; i<590; i++) { th = tlDequeue(prioliste1); mtDelThread(th); } printList(prioliste1, "prioliste1, after 600 SortIns and 590 pops"); getchar(); printList(queue1, "queue1 before end"); getchar(); // just to wait here printList(queue2, "queue2 before end"); getchar(); printList(prioliste2, "prioliste2, before end"); getchar(); // just to wait here tlDelList(queue1); tlDelList(queue2); tlDelList(prioliste1); tlDelList(prioliste2); }