cProgHW2Part1

cProgHW2Part1 - int block, int lblock) //first-last blocks...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
C PROGRAMMING HOMEWORK 2 PART 1 /******************* Homework Assignment 2 Part 1 By: /******************/ #include <stdio.h> #include <string.h> typedef char *string; void printfunc(string[], int , int ); void sortfunc(string[], int , int ); void swapper(string[], int , int ); int main() { char w0[16]="enter", w1[16]="drive", w2[16]="real", w3[16]="cage", w4[16]="bit"; char w5[16]="fall", w6[16]="apple", w7[16]="bad", w8[16]="good", w9[16]="high"; string array[]={w0, w1, w2, w3, w4, w5, w6, w7, w8, w9}; printf("The original array is:\n\n"); printfunc(array, 0, 9); //0-9 first and last blocks printf ("\n\nThe strings are sorted as follows: \n\n"); sortfunc(array, 0, 9); printf("\n"); system ("PAUSE"); //to pause program. return 0; } void printfunc(string array[],
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int block, int lblock) //first-last blocks { int counter; //declared outside loop for (counter=0; counter&lt;=lblock; counter++) //to avoid errors. printf (&quot;%6s&quot;, array[counter]); printf(&quot;\n&quot;); } void sortfunc(string array, int block, int lblock) { int counter, nextBlock, swapnum=1; for (; block&lt;lblock &amp;&amp; swapnum; lblock--) //; used for syntax rules. { swapnum = 0; for (counter=block; counter&lt;lblock; counter++) if (strcmp (array[counter], array[counter+1]) &gt; 0) { nextBlock= counter+1; swapper(array, counter, nextBlock); swapnum = 1; } printfunc(array,0,9); } } void swapper(string array, int i, int j) { string store; store = array[i]; array[i]= array[j]; array[j]= store; }...
View Full Document

Page1 / 2

cProgHW2Part1 - int block, int lblock) //first-last blocks...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online