cProgHW3Part3

cProgHW3Part3 - system("PAUSE");...

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 3 /******************* Homework Assignment 3 Part 3-insortStructP.c 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 insortstructP(person*, int , int ); void printfunc(person*, int , int ); void swapper(person*, person, int ); int main() { FILE *infile; infile= fopen(INPUT_FILE, "r"); if (infile == NULL) { printf("Cannot open file!\n" INPUT_FILE); printf("Terminating program. ..\n"); system("PAUSE"); } person club[20], *index[]; int i, count; printf("%3i input fields. 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); index[i]=&club[i]; } printfunc(index, 0, count-1); printf("Array: above at start, below exchange sort:\n"); insortst(index, 0, count-1); printfunc(index, 0, count-1);
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: system(&quot;PAUSE&quot;); return 0; } 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;); } void insortStructP(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); } }...
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

cProgHW3Part3 - system(&amp;amp;quot;PAUSE&amp;amp;quot;);...

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