cProgHW3Part1

cProgHW3Part1 - printf("Above array is shown...

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

View Full Document Right Arrow Icon
C PROGRAMMING HOMEWORK 3 PART 1 /******************* Homework Assignment 3 Part 1-Integer sort By: /******************/ #include <stdio.h> #include <stdlib.h> #define INPUT_FILE "inputfile.in" void insortfunc( int [], int , int ); void printfunc( int [], int , int ); void swapper( int [], int , int ); int main() { FILE *infile; if (infile == NULL ) { printf("Cannot open file, " INPUT_FILE "\n"); printf("Terminating program. ..\n"); system("PAUSE"); } infile= fopen(INPUT_FILE, "r"); int i0[16], i1[16], i2[16], i3[16], i4[16]; //integers int i5[16], i6[16], i7[16], i8[16], i9[16]; int array[]={i0, i1, i2, i3, i4, i5, i6, i7, i8, i9}; int counter, inputvar, store; for (counter=0; counter<10; counter++) //to fill array strings { fgets(array[counter], 16, infile); } printf("\n\nYour array is:\n\n"); printfunc(array, 0, 9);
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: printf(&quot;Above array is shown being insertion sorted below:\n&quot;); insort(array, 0, 9); printf(&quot;\n&quot;); system (&quot;PAUSE&quot;); return 0; } void insortfunc( int array, int block, int lblock) { int i, j, integer; for (i=lblock; i&gt;block; --i) { integer = array[i-1]; for (j=i; j&lt;=lblock &amp;&amp; integer&gt;array[j]; j++) swapper(array, integer, j); } } void swapper( int array, int integer, int j) { array[j-1] = array[j]; array[j-1] = integer; printerfunc(array, 0, 9); } void printfunc( int array, int block, int lblock) //first-last blocks { int counter; //declared outside loop for (counter=0; counter&lt;=lblock; counter++) //to avoid errors. printf (&quot;%4i&quot;, array[counter]); printf(&quot;\n&quot;); }...
View Full Document

Page1 / 2

cProgHW3Part1 - printf(&amp;amp;quot;Above array is shown...

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