cProgHW3Part2

cProgHW3Part2 - insortstruct(club, 0, count-1);...

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 2 /******************* Homework Assignment 3 Part 2-struct array By: /******************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #define INPUT_FILE "inputfile.in" typedef char *string; typedef struct person { char name[14]; int age; double height; } person; void insortStruct(person[], int , int ); void printfunc(person[], int , int ); void swapper(person[], person, int ); int main() { FILE *infile; if (infile == NULL) { printf("Cannot open file!\n" INPUT_FILE); printf("Terminating program. ..\n"); system("PAUSE"); } infile= fopen(INPUT_FILE, "r"); person club[20]; int i, count; fscanf(infile, "%i", &count); printf("%3i input sets. NAME AGE HEIGHT(FT)\n", count); for (i=0; i<count; i++) fscanf(infile, "%s %i %lg", &club[i].name, &club[i].age, &club[i].height); printfunc(club, 0, count-1); printf("Array: above at start, below exchange sort:\n");
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: insortstruct(club, 0, count-1); printfunc(club, 0, count-1); } void insortStruct(person array, int block, int lblock) { int i, j; person store; for (i=lblock; i&gt;block; --i) { store = array[i-1]; for (j=i; j&lt;=lblock &amp;&amp; strcmp(store.name,array[j].name)&lt;0; j++) swapper(array, store, j); } } void swapper(person array, person integer, int j) { array[j-1] = array[j]; array[j-1] = integer; printerfunc(array, 0, 9); } void printfunc(person 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;%20s%9i%9.2f\n&quot;, array[counter].name, array[counter].age, array[counter].height); printf(&quot;\n&quot;); }...
View Full Document

Page1 / 2

cProgHW3Part2 - insortstruct(club, 0, count-1);...

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