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

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<=lblock; counter++) //to avoid errors. printf ("%6s", array[counter]); printf("\n"); } void sortfunc(string array, int block, int lblock) { int counter, nextBlock, swapnum=1; for (; block<lblock && swapnum; lblock--) //; used for syntax rules. { swapnum = 0; for (counter=block; counter<lblock; counter++) if (strcmp (array[counter], array[counter+1]) > 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

This note was uploaded on 03/30/2008 for the course CS 212 taught by Professor Dr.frey during the Spring '06 term at New Haven.

Page1 / 2

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

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