Tuesday 16 August 2011

C database to keep track of and organise your contact details.


A website of mine which includes downloads for a C and Pascal is http://tarkastatistics.webs.com/

This is a database which will run on Linux to organise your contact details. It can be compiled from a terminal using the GNU compiler. The command is gcc filename. This creates an output file called a.out. It can be renamed using the command mv a.out newfilename. The command to run the program is ./newfilename.
 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100

struct addr {
char name[40];
char street[40];
char district[40];
char town[40];
char county[40];
char country[40];
char postcode[40];
char telno[40];
char email[40];
}addr_list[MAX];

struct addr temp;
int counter;
void init_list(void), enter(void);
void delete(void), list(void);
void load(void), save(void), sort(void);
void loadbackup(void), outputthree(void);
void outputtwo(void), search(void);
void readLine(char buffer[]);
void swap(int u, int v);
int main(void)
{
int choice;
char s[80];
counter = 0;
init_list();
for(;;) {
printf("\n");
printf("1.  Create a record\n");
printf("2.  Delete a record\n");
printf("3.  List the file\n");
printf("4.  Save the file\n");
printf("5.  Load the file\n");
printf("6.  Sort the file\n");
printf("7.  Search\n");
printf("8.  Save to a back up file\n");
printf("9.  Load from a backup file\n");
printf("10. Output to a text file for printing or import into wp\n");
printf("11. Quit\n");
do {
printf("\nEnter your choice: ");
readLine(s);
choice=atoi(s);
}while(choice < 0 && choice > 11);
switch(choice) {
case 1: enter();
break;
case 2: delete();
break;
case 3: list();
break;
case 4: save();
break;
case 5: load();
break;
case 6: sort();
break;
case 7: search();
break;
case 8: outputtwo();
break;
case 9: loadbackup();
break;
case 10: outputthree();
break;
case 11: exit(0);
}
}
return 0;
}

void init_list(void)
{
register int t;

for(t=0; t<MAX; ++t) addr_list[t].name[0] ='\0';
}

void enter(void)
{
char s[40];
int i;
for(i=1; i<MAX; i++)
if(!*addr_list[i].name)
break;
if(i==MAX)
{
printf("Subscriber array full\n");
return;
}
printf("Enter information on new customer\n");

printf("Enter name: ");
readLine(addr_list[i].name);

printf("Enter street: ");
readLine(addr_list[i].street);

printf("Enter district / parish: ");
readLine(addr_list[i].district);

printf("Enter town / city: ");
readLine(addr_list[i].town);

printf("Enter county: ");
readLine(addr_list[i].county);

printf("Enter country: ");
readLine(addr_list[i].country);

printf("Enter postcode: ");
readLine(addr_list[i].postcode);

printf("Enter telephone number: ");
readLine(addr_list[i].telno);

printf("Enter email address: ");
readLine(addr_list[i].email);
counter=counter+1;
}



void delete(void)
{
int t;
int u;
printf("enter a record number #: ");
scanf("%i", &t);
for(u=t; u<=counter; u++){
strncpy(addr_list[u].name, addr_list[u+1].name, 40);
strncpy(addr_list[u].street, addr_list[u+1].street, 40);
strncpy(addr_list[u].district, addr_list[u+1].district, 40);
strncpy(addr_list[u].town, addr_list[u+1].town, 40);
strncpy(addr_list[u].county, addr_list[u+1].county, 40);
strncpy(addr_list[u].country, addr_list[u+1].country, 40);
strncpy(addr_list[u].postcode, addr_list[u+1].postcode, 40);
strncpy(addr_list[u].telno, addr_list[u+1].telno, 40);
strncpy(addr_list[u].email, addr_list[u+1].email, 40);
}
addr_list[counter].name[0] = '\0';
addr_list[counter].street[0] = '\0';
addr_list[counter].district[0] = '\0';
addr_list[counter].town[0] = '\0';
addr_list[counter].county[0] = '\0';
addr_list[counter].country[0] = '\0';
addr_list[counter].postcode[0] = '\0';
addr_list[counter].telno[0] = '\0';
addr_list[counter].email[0] = '\0';
counter = counter -1;
}

void list(void)
{
register int t;
int count;
count=0;
for(t=1; t<=counter; t++) {
count = count +1;
printf("Record number: %i\n",count);
printf("%s\n", addr_list[t].name);
printf("%s\n", addr_list[t].street);
printf("%s\n", addr_list[t].district);
printf("%s\n", addr_list[t].town);
printf("%s\n", addr_list[t].county);
printf("%s\n", addr_list[t].country);
printf("%s\n", addr_list[t].postcode);
printf("%s\n", addr_list[t].telno);
printf("%s\n", addr_list[t].email);
printf("\n");
}
}

void sort(void)
{
register int u;
register int v;
for(u=1; u<counter; u++)
for (v=u+1; v<=counter; v++){
if( strcmp(addr_list[u].name, addr_list[v].name) >0){
swap(u, v);
}
}
}

void swap(int u, int v)
{
strncpy(temp.name, addr_list[u].name, 40);
strncpy(temp.street, addr_list[u].street, 40);
strncpy(temp.district, addr_list[u].district, 40);
strncpy(temp.town, addr_list[u].town, 40);
strncpy(temp.county, addr_list[u].county, 40);
strncpy(temp.country, addr_list[u].country, 40);
strncpy(temp.postcode,addr_list[u].postcode, 40);
strncpy(temp.telno, addr_list[u].telno, 40);
strncpy(temp.email, addr_list[u].email, 40);
strncpy(addr_list[u].name, addr_list[v].name, 40);
strncpy(addr_list[u].street, addr_list[v].street, 40);
strncpy(addr_list[u].district, addr_list[v].district, 40);
strncpy(addr_list[u].town, addr_list[v].town, 40);
strncpy(addr_list[u].county, addr_list[v].county, 40);
strncpy(addr_list[u].country, addr_list[v].country, 40);
strncpy(addr_list[u].postcode, addr_list[v].postcode, 40);
strncpy(addr_list[u].telno, addr_list[v].telno, 40);
strncpy(addr_list[u].email, addr_list[v].email, 40);
strncpy(addr_list[v].name, temp.name, 40);
strncpy(addr_list[v].street, temp.street, 40);
strncpy(addr_list[v].district, temp.district, 40);
strncpy(addr_list[v].town, temp.town, 40);
strncpy(addr_list[v].county, temp.county, 40);
strncpy(addr_list[v].country, temp.country, 40);
strncpy(addr_list[v].postcode, temp.postcode, 40);
strncpy(addr_list[v].telno, temp.telno, 40);
strncpy(addr_list[v].email, temp.email, 40);

}
void save(void)
{
FILE *fp;
register int i;

if((fp=fopen("maillist", "wb"))==NULL) {
printf("Cannot open file.\n");
return;
}

for(i=1; i<MAX; i++)
if(*addr_list[i].name)
if(fwrite(&addr_list[i],
sizeof(struct addr), 1, fp)!=1)
printf("File write error.\n");

fclose(fp);
}

void loadbackup(void)
{
FILE *fp;
register int i;
char filename[30];
printf("Enter a file name.\n");
scanf("%s",filename);
printf("\n");

if((fp=fopen(filename, "rb"))==NULL) {
printf("Cannot open file,\n");
return;
}

init_list();
for(i=1;  i<MAX; i++){
if(fread(&addr_list[i],
sizeof(struct addr), 1, fp)!=1) {
if(feof(fp)) break;
printf("File read error.\n");
}
counter=counter+1;
}
fclose(fp);
}



void load(void)
{
FILE *fp;
register int i;

if((fp=fopen("maillist", "rb"))==NULL) {
printf("Cannot open file,\n");
return;
}

init_list();
for(i=1;  i<MAX; i++){
if(fread(&addr_list[i],
sizeof(struct addr), 1, fp)!=1) {
if(feof(fp)) break;
printf("File read error.\n");
}
counter=counter +1;
}
fclose(fp);
}


void outputthree(void)
{
int t;
int count;
FILE *stream;
char filename[30];
count = 0;
printf("Enter a file name.\n");
scanf("%s",filename);
printf("\n");
stream = fopen(filename, "w+");
for(t=1; t<MAX; t++) {
if(addr_list[t].name[0]) {
count = count +1;
fprintf(stream,"%i\n",count);
fprintf(stream,"%s\n", addr_list[t].name);
fprintf(stream,"%s\n", addr_list[t].street);
fprintf(stream,"%s\n", addr_list[t].district);
fprintf(stream,"%s\n", addr_list[t].town);
fprintf(stream,"%s\n", addr_list[t].county);
fprintf(stream,"%s\n", addr_list[t].country);
fprintf(stream,"%s\n", addr_list[t].postcode);
fprintf(stream,"%s\n", addr_list[t].telno);
fprintf(stream,"%s\n", addr_list[t].email);
fprintf(stream,"\n");
}
}
fclose(stream);
return;
}



void outputtwo(void)
{
FILE *fp;
register int i;
char filename[30];
printf("Enter a file name.\n");
scanf("%s",filename);
printf("\n");
if((fp=fopen(filename, "wb"))==NULL) {
printf("Cannot open file.\n");
return;
}

for(i=1; i<MAX; i++)
if(*addr_list[i].name)
if(fwrite(&addr_list[i],
sizeof(struct addr), 1, fp)!=1)
printf("File write error.\n");

fclose(fp);
}

void search(void)
{
int i;
int count;
char s[40];
count=0;
printf("\nEnter a name.\n");
readLine(s);
for(i=1;i<MAX;i++)
{
if(addr_list[i].name[0]) {
count = count +1;
}

if (strcmp(s, addr_list[i].name)==0)
{
printf("\nRecord number: %i\n", count);
printf("\nName: %s\n",addr_list[i].name);
printf("\nStreet: %s\n",addr_list[i].street);
printf("\nDistrict: %s\n",addr_list[i].district);
printf("\nTown: %s\n",addr_list[i].town);
printf("\nCounty: %s\n",addr_list[i].county);
printf("\nCountry: %s\n",addr_list[i].country);
printf("\nPostcode:%s\n",addr_list[i].postcode);
printf("\nTelephone number: %s\n",addr_list[i].telno);
printf("\nEmail address: %s\n",addr_list[i].email);
printf("\n");
}
}
}

void readLine(char buffer[])
{
char character;
int i=0;
do
{
character=getchar();
buffer[i]=character;
++i;
}
while(character !='\n');
buffer[i-1]='\0';
}

C database to for organising your music collection.

This is a database which will run on Linux to organise your music collection. It can be compiled from a terminal using the GNU compiler. The command is gcc filename. This creates an output file called a.out. It can be renamed using the command mv a.out newfilename. The command to run the program is ./newfilename.


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 500

struct cd {
char artist[30];
char title[40];
char style[20];
}cd_list[MAX];

struct cd temp;
int counter;

void init_list(void), enter(void);
void delete(void), list(void);
void load(void), save(void), sort(void);
void copy(void), loadbackup(void), output(void);
void outputtwo(void), search(void), loadbackuptwo(void);
void searchbytitle(void);
int menu_select(void), find_free(void);

int main(void)
{
char choice;

init_list();
for(;;) {
choice = menu_select();
switch(choice) {
case 1: enter();
break;
case 2: delete();
break;
case 3: list();
break;
case 4: save();
break;
case 5: load();
break;
case 6: sort();
break;
case 7: copy();
break;
case 8: loadbackup();
break;
case 9: output();
break;
case 10: outputtwo();
break;
case 11: loadbackuptwo();
break;
case 12: search();
break;
case 13: searchbytitle();
break;
case 14: exit(0);
}
}
}

void init_list(void)
{
register int t;

for(t=1; t<MAX; ++t) cd_list[t].artist[0] ='\0';
}
int menu_select(void)
{
char s[80];
int c;

printf("\n");
printf("1.  Enter a CD\n");
printf("2.  Delete a CD\n");
printf("3.  List the file\n");
printf("4.  Save the file\n");
printf("5.  Load the file\n");
printf("6.  Sort the file\n");
printf("7.  Copy the file after saving\n");
printf("8.  Load the copied file\n");
printf("9.  Output to text file for printing or word processing\n");
printf("10. Output to a backup file with a name of your choice\n");
printf("11. Load from a backup file with a name of your choice\n");
printf("12. Search by artist\n");
printf("13. Search by title\n");
printf("14. Quit\n");
do {
printf("\nEnter your choice: ");
gets(s);
c = atoi(s);
} while(c<0 || c>14);
return c;
}

void enter(void)
{
int slot;
char s[80];

slot = find_free();

if(slot==-1) {
printf("\nList Full");
return;
}

printf("Enter artist: ");
gets(cd_list[slot].artist);
printf("Enter title: ");
gets(cd_list[slot].title);
printf("Enter style, (A)mbient, (B)lues, (F)olk, (I)nstrumental, \n");
printf("(J)azz, (M)editation, (N)ew age, (R)ock, (S)oul, (T)heme: ");
gets(cd_list[slot].style);
counter = counter +1;
}

int find_free(void)
{
register int t;

for(t=1; cd_list[t].artist[0] && t<MAX; t++)

if(t==MAX) return -1;
return t;
}

void delete(void)
{
int t;
int u;
printf("enter a record number #: ");
scanf("%i", &t);
for(u=t; u<=counter; u++){
strncpy(cd_list[u].artist, cd_list[u+1].artist, 30);
strncpy(cd_list[u].title, cd_list[u+1].title, 40);
strncpy(cd_list[u].style, cd_list[u+1].style, 20);
}
cd_list[counter].artist[0] = '\0';
cd_list[counter].title[0] = '\0';
cd_list[counter].style[0] = '\0';
counter = counter -1;

}

void list(void)
{
register int t;
int count;
count = 0;
for(t=1; t<MAX; t++) {
if(cd_list[t].artist[0]) {
count = count +1;
printf("CD number %i\n",count);
printf("%s\n", cd_list[t].artist);
printf("%s\n", cd_list[t].title);
printf("%s\n", cd_list[t].style);
printf("\n");
}
}
printf("\n\n");
}

void sort(void)
{
register int u;
register int t;
for (t=1; t<counter; t++){
for (u=t+1; u<=counter; u++)
if( strcmp(cd_list[t].artist, cd_list[u].artist) >0){
strncpy(temp.artist, cd_list[t].artist, 30);
strncpy(temp.title, cd_list[t].title, 40);
strncpy(temp.style, cd_list[t].style, 20);
strncpy(cd_list[t].artist, cd_list[u].artist, 30);
strncpy(cd_list[t].title, cd_list[u].title, 40);
strncpy(cd_list[t].style, cd_list[u].style, 20);
strncpy(cd_list[u].artist, temp.artist, 30);
strncpy(cd_list[u].title, temp.title, 40);
strncpy(cd_list[u].style, temp.style, 20);
}
}
}

void save(void)
{
FILE *fp;
register int i;

if((fp=fopen("cdlist", "wb"))==NULL) {
printf("Cannot open file.\n");
return;
}

for(i=1; i<MAX; i++)
if(*cd_list[i].artist)
if(fwrite(&cd_list[i],
sizeof(struct cd), 1, fp)!=1)
printf("File write error.\n");

fclose(fp);
}

void load(void)
{
FILE *fp;
register int i;
if((fp=fopen("cdlist", "rb"))==NULL) {
printf("Cannot open file,\n");
return;
}

init_list();

counter = 0;
for(i=1;  i<MAX; i++){
if(fread(&cd_list[i],
sizeof(struct cd), 1, fp)!=1) {
if(feof(fp)) break;
printf("File read error.\n");
}
counter = counter +1;
}
fclose(fp);
}

void copy(void)
{
FILE *in, *out;
int c;
if ((in = fopen ("cdlist", "r")) ==NULL){
printf("Cant open %s file for reading.\n","cdlist");
return 1;
}

if ((out = fopen("cdlistbackup", "w")) ==NULL){
printf("Cant open %s for writing.\n", "cdlistbackup");
return 2;
}

while ((c = getc (in)) !=EOF)
putc (c, out);

fclose (in);
fclose(out);
printf("File has been copied.\n");
return 0;
}


void loadbackup(void)
{
FILE *fp;
register int i;

if((fp=fopen("cdlistbackup", "rb"))==NULL) {
printf("Cannot open file,\n");
return;
}

init_list();
counter = 0;
for(i=1;  i<MAX; i++){
if(fread(&cd_list[i],
sizeof(struct cd), 1, fp)!=1) {
if(feof(fp)) break;
printf("File read error.\n");
}
counter = counter +1;
}
fclose(fp);
}


void output(void)
{
int t;
int count;
FILE *stream;
count =0;
stream = fopen("cddboutput.txt", "w+");
for(t=1; t<MAX; t++) {
if(cd_list[t].artist[0]) {
count = count + 1;
fprintf(stream,"CD number %i\n",count);
fprintf(stream,"%s\n", cd_list[t].artist);
fprintf(stream,"%s\n", cd_list[t].title);
fprintf(stream,"%s\n", cd_list[t].style);
fprintf(stream,"\n");
}
}
fclose(stream);
return;
}

void outputtwo(void)
{
FILE *fp;
register int i;
char filename[30];
printf("Enter a file name.\n");
gets(filename);
printf("\n");
if((fp=fopen(filename, "wb"))==NULL) {
printf("Cannot open file.\n");
return;
}

for(i=1; i<MAX; i++)
if(*cd_list[i].artist)
if(fwrite(&cd_list[i],
sizeof(struct cd), 1, fp)!=1)
printf("File write error.\n");

fclose(fp);
}


void loadbackuptwo(void)
{
register int i;
FILE *fp;
char filename[30];
printf("Enter a file name.\n");
gets(filename);
printf("\n");

if((fp=fopen(filename, "rb"))==NULL) {
printf("Cannot open file,\n");
return;
}

init_list();
counter = 0;
for(i=1;  i<MAX; i++){
if(fread(&cd_list[i],
sizeof(struct cd), 1, fp)!=1) {
if(feof(fp)) break;
printf("File read error.\n");
}
counter = counter +1;
}
fclose(fp);
}


void search(void)
{
int i;
char s[30];
printf("\nEnter an artist.\n");
gets(s);
for(i=1;i<MAX;i++)
{
if (strcmp(s, cd_list[i].artist)==0)
{
printf("\nRecord number: %i\n",i);
printf("\nArtist: %s\n",cd_list[i].artist);
printf("\nTitle: %s\n",cd_list[i].title);
printf("\nStyle: %s\n",cd_list[i].style);
printf("\n");
}
}
}

void searchbytitle(void)
{
int i;
char s[30];
printf("\nEnter a title.\n");
gets(s);
for(i=1;i<MAX;i++)
{
if (strcmp(s, cd_list[i].title)==0)
{
printf("\nRecord number: %i\n",i);
printf("\nArtist: %s\n",cd_list[i].artist);
printf("\nTitle: %s\n",cd_list[i].title);
printf("\nStyle: %s\n",cd_list[i].style);
printf("\n");
}
}
}

Pascal database to keep track of and organise your contact details.

This is a database to run on Linux which organises your contacts. It can be compiled from a terminal using the free Pascal compiiler. The command to compile is fpc filename. The program can then be run with the command ./filename.

program records1(input, output);
uses crt;
{const maxsize = 99;}
type
address = record
name : string[40];
street : string[40];
area : string[40];
town : string[40];
county : string[40];
postcode : string[40];
telephone : string[40];
email : string[40];
end;

var
book : array[1..50] of address;
diskfile : file of address;
counter : integer;
choice : integer;


procedure save;
var
loop : integer;
begin
assign(diskfile,'address.data');
rewrite(diskfile);
for loop := 1 to counter  do
write(diskfile,book[loop]);
close(diskfile)
end;

procedure load;
begin
assign(diskfile,'address.data');
reset(diskfile);
while not eof(diskfile) do
begin
counter:= counter + 1;
read(diskfile, book[counter]);
end;
close(diskfile)
end;

procedure newaddress;
begin
counter := counter +1;
textbackground (cyan);
window(1, 1, 40, 40);
writeln('Enter name: ');
readln(book[counter].name);
writeln('Enter street: ');
readln(book[counter].street);
writeln('Area / district: ');
readln(book[counter].area);
writeln('Enter town / city: ');
readln(book[counter].town);
writeln('Enter county: ');
readln(book[counter].county);
writeln('Enter postcode: ');
readln(book[counter].postcode);
writeln('Enter telephone number: ');
readln(book[counter].telephone);
writeln('Enter email address: ');
readln(book[counter].email);
end;


procedure display;
var
loop : integer;
begin
textbackground (green);
window(1, 1, 40, counter*10);
for loop := 1 to counter  do
begin
writeln('RECORD NO. ',loop);
writeln(book[loop].name);
writeln(book[loop].street);
writeln(book[loop].area);
writeln(book[loop].town);
writeln(book[loop].county);
writeln(book[loop].postcode);
writeln(book[loop].telephone);
writeln(book[loop].email);
writeln('');
end;
end;

procedure search;
var
loop : integer;
target : string[40];
begin
window(1, 1, 40, 40);
textbackground(magenta);
writeln('Enter name to search for: ');
readln(target);
for loop := 1 to counter do
if book[loop].name = target
then begin
writeln(book[loop].name);
writeln(book[loop].street);
writeln(book[loop].area);
writeln(book[loop].town);
writeln(book[loop].county);
writeln(book[loop].postcode);
writeln(book[loop].telephone);
writeln(book[loop].email);
writeln('');
end;
end;

procedure delete;
var
target : integer;
loop : integer;
begin
window(1, 1, 40, 40);
textbackground(red);
writeln('Record number? ');
readln(target);
if(target>0) and (target<=counter)
then begin
for loop := target to counter  do
book[loop] := book[loop+1];
counter := counter -1;
end;
end;

procedure sort;
var
noswaps : boolean;
current : address;
x : integer;
begin
repeat
noswaps := true;
for x := 1 to counter -1 do
begin
if book[x].name > book[x + 1].name then
begin
current := book[x];
book[x] := book[x+1];
book[x+1] := current;
noswaps := false;
end;
end;
until noswaps;
end;


begin
counter:= 0;
repeat
window(1, 1, 40, 30);
textbackground(blink);
writeln('');
writeln('Address book');
writeln('Load file 1');
writeln('New address 2');
writeln('Display addresses 3');
writeln('Select by name 4');
writeln('Delete record 5');
writeln('Sort records 6');
writeln('Save 7');
writeln('Exit 8');
writeln('Choose ...');
readln(choice);

if choice = 1 then load;
if choice = 2 then newaddress;
if choice = 3 then display;
if choice = 4 then search;
if choice = 5 then delete;
if choice = 6 then sort;
if choice = 7 then save;
until choice = 8;
end.

Pascal database for organising your music collection.

This is a database to run on Linux which organises your music collection. It can be compiled from a terminal using the free Pascal compiiler. The command to compile is fpc filename. The program can then be run with the command ./filename.

Ref: Pascal made simple by Peter McBride

program records1(input, output);
uses crt, printer;

type
cd = record
artist : string[40];
title : string[40];
style : char;
end;

var
collection : array[1..50] of CD;
diskfile : file of CD;
counter : integer;
choice : integer;

procedure sort;
var
noswaps : boolean;
current : cd;
x : integer;
w :integer;
begin
{repeat
noswaps := true;}
for w := 1 to counter do
for x := 1 to counter -2 do
begin
if collection[x].artist > collection[x + 1].artist then
begin
current := collection[x];
collection[x] := collection[x+1];
collection[x+1] := current;
{noswaps := false;}
end;
end;
{until noswaps;}
end;


procedure save;
var
loop : integer;
begin
assign(diskfile,'cd.dta');
rewrite(diskfile);
for loop := 1 to counter - 1 do
write(diskfile,collection[loop]);
close(diskfile)
end;

procedure load;
begin
assign(diskfile,'cd.dta');
reset(diskfile);
while not eof(diskfile) do
begin
read(diskfile, collection[counter]);
counter := counter + 1;
end;
close(diskfile)
end;

procedure newcd;
begin
with collection[counter] do
begin
write('Enter artist: ');
readln(artist);
write('Enter title: ');
readln(title);
writeln('Enter style (A)mbient, (B)lues, (C)lassical, (F)olk, (I)nstrumental,');
writeln('(J)azz, (M)editation, (N)ew age, (R)ock, (S)oul, (T)hemes: ');
readln(style);
end;
counter := counter + 1;
end;

procedure showone(disk : CD; num : integer);
begin
if disk.artist[1] <> chr(255) then
with disk do
begin
writeln('CD NO. ',num);
writeln(artist);
writeln(title);
writeln(style);
end;
end;

procedure display;
var
loop : integer;
begin
for loop := 1 to counter - 1 do
showone(collection[loop],loop);
end;

procedure search;
var
loop : integer;
target : string[40];
begin
writeln('Enter artist to search for: ');
readln(target);
for loop := 1 to counter do
if collection[loop].artist = target
then showone(collection[loop],loop);
end;

procedure delete;
var
target : integer;
loop : integer;
begin
write('Record number? ');
readln(target);
if(target>0) and (target<counter)
then begin
for loop := target to counter - 1 do
collection[loop] := collection[loop+1];
counter := counter -1;
end;
end;

procedure print;
var
i : integer;
f : text;
begin
for i:= 1 to counter-1 do
begin
writeln(lst,'RECORD NO. ',i);
writeln(lst, collection[i].artist);
writeln(lst, collection[i].title);
writeln(lst, collection[i].style);
writeln(lst,'');
end;
close(lst);
assignlst (f,'|/usr/bin/lpr -m');
rewrite(f);
for i:= 1 to counter-1 do
begin
writeln(f,'RECORD NO. ',i);
writeln(f, collection[i].artist);
writeln(f, collection[i].title);
writeln(f, collection[i].style);
writeln(f,'');
end;
close (f);
end;


begin
counter:= 1;
{load;}
writeln('CD collection organiser');
repeat
{while choice <> '6' do
begin}
writeln('Load file 1');
writeln('New CD 2');
writeln('Display collection 3');
writeln('Select by artist 4');
writeln('Delete record 5');
writeln('Sort records 6');
writeln('Save file 7');
writeln('Print 8');
writeln('Exit 9');
readln(choice);
{case choice of
'1' : load;
'2' : newcd;
'3' : display;
'4' : search;
'5' : delete;
'6' : save;
end;}
if choice = 1 then load;
if choice = 2 then newcd;
if choice = 3 then display;
if choice = 4 then search;
if choice = 5 then delete;
if choice = 6 then sort;
if choice = 7 then save;
if choice = 8 then print;
until choice = 9;
end.