My Code is now loking like this!.......... I am quite amazed with myself really..... not up to much but on the way to working! Can't work out sorting for the life of me!!!!!!!!!!!
Any help as always greatfully appreciated!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
/* {char surname [20];
char first [20];
long reg [9]
char dob [9]; }RECORD;
int comp(const void *a,const void *b);*/
void main ()
{
char prisoner[10][60];
int count2=0;
int count1=0;
FILE*pfile;
int choice;
puts(" PRISONERS RECORD VIEWER\n\n");
puts("Fname Sname Reg DOB\n");
pfile=fopen("prisoner.txt","r");
if (pfile==NULL)
{printf("Cannot find prisoner file\n");}
for(;count1<10;count1++)
{fgets(prisoner[count1],60, pfile);}
printf("\n\n\n\n\n\n\n\n\n\n\n");
menu:
printf("\n\n\n\n\nChoose from the option list below");
printf("or quit\n\n");
printf("OPTIONS :- First(1) Last(2) Previous(3) Next(4) Sort(5) ");
printf("Quit(6)\n\n\n\n");
scanf("%d",&choice);
switch (choice)
{ case 1:
count2=0;
printf("\t\t\tPrisoner Record Viewer\n\n");
printf("Fname Sname Reg DOB\n\n");
printf("%s",prisoner[count2]);
printf("\n\n\n\n\n\n\n\n\n\n\n");
goto menu;
case 2:
count2=9;
printf("\t\t\tPrisoner Record Viewer\n\n");
printf("Fname Sname Reg DOB\n\n");
printf("%s",prisoner[count2]);
printf("\n\n\n\n\n\n\n\n\n\n\n");
goto menu;
case 3:
count2=count2-1;
if (count2<0)
count2=0;
printf("\t\t\tPrisoner Record Viewer\n\n");
printf("Fname Sname Reg DOB\n\n");
printf("%s",prisoner[count2]);
printf("\n\n\n\n\n\n\n\n\n\n\n");
goto menu;
case 4:
count2=count2+1;
if (count2>9)
count2=9;
printf("\t\t\tPrisoner Record Viewer\n\n");
printf("Fname Sname Reg DOB\n\n");
printf("%s",prisoner[count2]);
printf("\n\n\n\n\n\n\n\n\n\n\n");
goto menu;
/* case 5 : SORTING!!!!!!!!! */
case 6:
exit(0);
default:
printf("\n\n\n\n\n\n\n\n\n\n\n !NOT RECOGNISED!");
printf("please re-enter using keys 1-6 only");
goto menu;
}
prisoner.txt ==========
Nudd, Bob, 00266989, 30-07-80,
Ward, Laura, 88998563, 25-09-64,
Best, George, 01005645, 10-10-54,
Moffat, Bobby 00254657, 25-06-48,
Braun, Ross, 02025984, 12-05-49,
O'Sullivan, Ron, 89215658, 12-03-62,
Brown, Wesley, 86456856, 10-12-58,
Chan, Jackie, 76856854, 01-10-50,
Garbo, Greta, 64856213, 19-06-66,
Charlton, Bobby, 66845123, 18-03-48,
Anyone know of anywhere on the web that gives the do's and donts of indentation? Thanks as ever Tom!