#include<stdio.h>
#include<conio.h>
#include<string.h>


struct book{
char title[30];
int book_isbn[13];
};book library


int x, found,count,y;
char title[20][30];


void setup()
{
	strcpy(title[0], "Wind In The Willows");
	strcpy(title[1], "Fright Night");
	strcpy(title[2], "Women From Venus, Men are from Mars");
	strcpy(title[3], "Happy Days");
	strcpy(title[4], "Gone Fishing");
	strcpy(title[5], "My Sql");
	strcpy(title[6], "About Nothing");
	strcpy(title[7], "Beowulf");
	strcpy(title[8], "Shopoholic");
	strcpy(title[9], "Programming for Leraners");
	strcpy(title[10], "I love You");
	strcpy(title[11], "cardinal");
	strcpy(title[12], "The Birds");
	strcpy(title[13], "Three Men and Mice");
	strcpy(title[14], "Stig Of The Dump");
	strcpy(title[15], "Nowhere");
	strcpy(title[16], "Zulu");
	strcpy(title[17], "Deal with It");
	strcpy(title[18], "Klaxons");
	strcpy(title[19], "Learn to speak Spanish");

	isbn[0]=1234777372037;
	isbn[1]=2345109283274;
	isbn[3]=3456280364781;
	isbn[4]=4567982745729;
	isbn[5]=5678111882763;
	isbn[6]=6789120356788;
	isbn[7]=7890999243552;
	isbn[8]=8901188826666;
	isbn[9]=9012224563728;
	isbn[10]=012312222112;
	isbn[11]=112344882773;
	isbn[12]=122309412036;
	isbn[13]=132300098765;
	isbn[14]=142333387887;
	isbn[15]=152322229999;
	isbn[16]=162322222000;
	isbn[17]=172311993873;
	isbn[18]=182333333221;
	isbn[19]=192300000000;

	count=20;
}
void title()
{
for(x=0;x<20;x++)
{
	printf("\n Enter a Title ");
	gets(sname);

	printf("\n Please Enter Title:");
	gets(title);
	found=0;
	for(x=0;x<20;x++)
	if(strcmpi(title[x])==0)
	{
	printf("\n%s",title[x]);
	found=1;
	}
	if(found==0)
	printf("\n Book not found on Database ");
	getch();
}
void searched()
{
}
void sort()
{
int swap;


	do
{
	swap=0;
for (x=0;x<count-1;x++)
{
if(strcmpi(book[x].title,book[x+1].title)>0)

{
temp=book[x];
book[x]=book[x+1];
book[x+1]=temp;
swap=1;
}}
}while(swap!=0);
	for(x=0;x<count;x++)
	{
	printf("\n%s %d",book[x].title,book[x].isbn);
	}
	getch();
}

void change()
{
}
void delstud()
{
	printf("\n Please Enter A Title:");
	gets(title);
	found=0;
	for(x=0;x<count;x++)
	if(strcmpi(title,book[x].title)==0)
	{
	printf("\n%s %d",book[x].title,book[x].isbn);
		found=1;
		for(y=x;y<count;y++)
		{
		book[y]=book[y+1];
		}


count=count-1;
	}
	if(found==0)
	printf("\n Book not found on Database ");
	getch();

}
void addbook()
{
if(count<30)
{
	printf("\n Enter a Name of a book");
	gets(book[count].title);
	printf("\nEnter new Book ISBN");
	scanf("%d",&book[count].isbn);
	count++;
}
else
{
	printf("\nDatabase Full");
	getche();
}
}
void writefile()
{

	FILE*f;
	f=fopen("book.dat","wb");
	for(x=0;x<count; x++)
	fwrite(&book[x],sizeof(struct books),1,f);

	fclose(f);
}
void readfile()
{
	FILE*f;
	count=1;
	if((f=fopen("book.dat","rb"))==NULL)
	{
	printf("\n book.dat file not found");
	getch();
	count=0;
	}
	else
	{
		do
		{
		count=count+1;
		fread(&book[count],sizeof(struct books),1,f);
		}while(!feof(f));
		fclose(f);
		}
	}

void menu()
{
     int choice;
     do
{
     clrscr();
     printf("\n\t\tl. \tSearch for Title");
     printf("\n\t\t2. \tSearch by ISBN");
     printf("\n\t\t3. \tSort
     printf("\n\t\t4. \tChange ISBN");
     printf("\n\t\t5. \tDelete BOOK");
     printf("\n\t\t6. \tAdd Book");
     printf("\n\t\t7. \tExit");
     printf("\n\t\t. \tEnter a Menu Choice->");
     scanf("%d", &choice);
     fflush(stdin);
     switch(choice)
{
     case 1:searchtitle();
     break;

     case 2:searched();
     break;

     case 3:sort();
     break;

     case 4:change();
     break;

     case 5:delbook();
     break;
     
     case 6:addbook();
     break;
     default: printf("\nInvalid Choice Entered");
     getch();
}
}    while (choice!=8);
}

void main()
{
setup();
menu();
}

dO i DO THIS AS A LIBRARY??
THANKS FOR ANY HELP

PS
i KNOW i HAVE A FEW ERRORS,LOL

do you mean the sort function beginning on line 84 ? Lines 97-100 look ok to me.

It comes up with loads of errors, im not sure for isbn, if i should change it to library, also that im not sure if i shud use the strcmpi line 72 and 69 may conflict.

thanks

strcpy(title[0] <<< SHOULD I CHANGE TITLE TO LIBRARY?

printf("\n Enter a Title ");
gets(sname);
printf("\n Please Enter Title:");
gets(title);
found=0;
for(x=0;x<20;x++)
if(strcmpi(title[x])==0)
{
printf("\n%s",title[x]);
found=1

THIS SEEMS TO BE A PROBLEM TOO

>>char title[20][30];

30 characters is too small because a couple of the strings you are copying are longer than that. Might be better to use pointers, then you don't have to worry a about it, unless you intend to change the text of the titles

char *title[] = {
"Wind In The Willows",
"Fright Night",
"Women From Venus, Men are from Mars",
"Happy Days",
"Gone Fishing",
"My Sql",
"About Nothing",
"Beowulf",
"Shopoholic",
"Programming for Leraners",
"I love You",
"cardinal",
"The Birds",
"Three Men and Mice",
"Stig Of The Dump",
"Nowhere",
"Zulu",
"Deal with It",
"Klaxons",
"Learn to speak Spanish",
};

You cant have strcmpi(title eh? lol thinks how many will be laughing at me,lol well i think for a lassie i give it a good try,lol

As for the other errors you mentioned just work through them one at a time. Fix an error then recompile to see new list of errors. Repeat until all errors are fixed.

Next time don't code so many lines without compiling and correcting your mistakes. Depending on the errors it might almost be more efficient to just start all over again and do it right this time. In the beginning you shouldn't write more than two or three lines of code before compiling. Even professional programmers don't write huge blocks of code without compiling and correcting errors.

You cant have strcmpi(title eh? lol thinks how many will be laughing at me,lol well i think for a lassie i give it a good try,lol

I don't know what you mean by that. And its stricmp() on the compilers I use. But your compiler may have a different name because that function is non-standard.

But yes, you can use stricmp() or strcmpi(), whichever you want to use.

#include<stdio.h>
#include<conio.h>
#include<string.h>

struct person{
char name[15];
int id;
}student[20],temp;

int x, found,count,y;
char names,sname[15];


void setup()
{
	strcpy(student[0].name, "Smith");
	strcpy(student[1].name, "Richards");
	strcpy(student[2].name, "Lawson");
	strcpy(student[3].name, "Smith");
	strcpy(student[4].name, "Bourne");
	strcpy(student[5].name, "Smart");
	strcpy(student[6].name, "Ward");
	strcpy(student[7].name, "Edwards");
	strcpy(student[8].name, "Andrews");
	strcpy(student[9].name, "Martin");
	strcpy(student[10].name, "Williams");
	strcpy(student[11].name, "cardinal");
	strcpy(student[12].name, "Davies");
	strcpy(student[13].name, "Edgar");
	strcpy(student[14].name, "Frank");
	strcpy(student[15].name, "Graham");
	strcpy(student[16].name, "Harris");
	strcpy(student[17].name, "Inglis");
	strcpy(student[18].name, "Jones");
	strcpy(student[19].name, "Knowles");

	student[0].id=1234;
	student[1].id=2345;
	student[2].id=3456;
	student[3].id=4567;
	student[4].id=5678;
	student[5].id=6789;
	student[6].id=7890;
	student[7].id=8901;
	student[8].id=9012;
	student[9].id=1333;
	student[10].id=1123;
	student[11].id=1223;
	student[12].id=1323;
	student[13].id=1423;
	student[14].id=1523;
	student[15].id=1623;
	student[16].id=1723;
	student[17].id=1823;
	student[18].id=1923;
	student[19].id=2000;

	count=20;
}
void searchname()
{


	printf("\n Please Enter Surname:");
	gets(sname);
	found=0;
	for(x=0;x<count;x++)
	if(strcmpi(sname,student[x].name)==0)
	{
	printf("\n%s %d",student[x].name,student[x].id);
		found=1;
	}
	if(found==0)
	printf("\n Surname not on Database ");
	getch();
}

void searched()
{
}
void sort()
{
int swap;


	do
{
	swap=0;
for (x=0;x<count-1;x++)
{
if(strcmpi(student[x].name,student[x+1].name)>0)

{
temp=student[x];
student[x]=student[x+1];
student[x+1]=temp;
swap=1;
}}
}while(swap!=0);
	for(x=0;x<count;x++)
	{
	printf("\n%s %d",student[x].name,student[x].id);
	}
	getch();
}
void change()
{

}
void delstud()
{
	printf("\n Please Enter Surname:");
	gets(sname);
	found=0;
	for(x=0;x<count;x++)
	if(strcmpi(sname,student[x].name)==0)
	{
	printf("\n%s %d",student[x].name,student[x].id);
		found=1;
		for(y=x;y<count;y++)
		{
		student[y]=student[y+1];
		}


count=count-1;
	}
	if(found==0)
	printf("\n Surname not on Database ");
	getch();

}
void addstudent()
{
if(count<30)
{
	printf("\n Enter a Name of a Student");
	gets(student[count].name);
	printf("\nEnter new student's ID");
	scanf("%d",&student[count].id);
	count++;
}
else
{
	printf("\nDatabase Full");
	getche();
}
}
void writefile()
{

	FILE*f;
	f=fopen("student.dat","wb");
	for(x=0;x<count; x++)
	fwrite(&student[x],sizeof(struct person),1,f);

	fclose(f);
}
void readfile()
{
	FILE*f;
	count=1;
	if((f=fopen("student.dat","rb"))==NULL)
	{
	printf("\nStudent.dat file not found");
	getch();
	count=0;
	}
	else
	{
		do
		{
		count=count+1;
		fread(&student[count],sizeof(struct person),1,f);
		}while(!feof(f));
		fclose(f);
		}
	}


void menu()
{
     int choice;
     do
{
     clrscr();
     printf("\n\t\tl. \tSearch for student");
     printf("\n\t\t2. \tSearch by ID");
     printf("\n\t\t3. \tSort Files");
     printf("\n\t\t4. \tChange ID number");
     printf("\n\t\t5. \tDelete Student");
     printf("\n\t\t6. \tAdd New Student");
     printf("\n\t\t7. \tExit Program");
     printf("\n\t\t. \tEnter a Menu Choice->");
     scanf("%d", &choice);
     fflush(stdin);
     switch(choice)
{
     case 1:searchname();
     break;

     case 2:searched();
     break;

     case 3:sort();
     break;

     case 4:change();
     break;

     case 5:delstud();
     break;

     case 6:addstudent();
     break;
     default: printf("\nInvalid Choice Entered");
     getch();
}
}    while (choice!=7);
}


void main()
{
setup();
menu();
writefile();
}

THIS IS MY ORGINAL ONE I DONE FOR STUDENT,LOL YOU SEE WHY I THOUGHT IT BE KINDA THE SAME?LOL

Thanks for your help much appreciated :)

so... what's your question now?

i tried compiling your original file from post #1 and i got about 100 errors.

okay, i dont know how far youve gotten, but your first problem with the original code is your confusion of the structure elements with independent variables.

here's what i think your intent is... try replacing this first part of your program, recompile and work on making the rest of your program follow this scheme.

(and more than replacing, try to understand how the structure elements are being referenced... i believe you did it correctly in your "student" example above)

struct library 
{
	char title[40];
	int isbn;
};

int x, found,count,y;
struct library book[30];

void setup()
{
	strcpy(book[0].title,  "Wind In The Willows");
	strcpy(book[1].title,  "Fright Night");
	strcpy(book[2].title,  "Women From Venus,  Men are from Mars");
	strcpy(book[3].title,  "Happy Days");
	strcpy(book[4].title,  "Gone Fishing");
	strcpy(book[5].title,  "My Sql");
	strcpy(book[6].title,  "About Nothing");
	strcpy(book[7].title,  "Beowulf");
	strcpy(book[8].title,  "Shopoholic");
	strcpy(book[9].title,  "Programming for Leraners");
	strcpy(book[10].title, "I love You");
	strcpy(book[11].title, "cardinal");
	strcpy(book[12].title, "The Birds");
	strcpy(book[13].title, "Three Men and Mice");
	strcpy(book[14].title, "Stig Of The Dump");
	strcpy(book[15].title, "Nowhere");
	strcpy(book[16].title, "Zulu");
	strcpy(book[17].title, "Deal with It");
	strcpy(book[18].title, "Klaxons");
	strcpy(book[19].title, "Learn to speak Spanish");
	strcpy(book[20].title, "");

	book[0].isbn  = 1234777372037;
	book[1].isbn  = 2345109283274;
	book[3].isbn  = 3456280364781;
	book[4].isbn  = 4567982745729;
	book[5].isbn  = 5678111882763;
	book[6].isbn  = 6789120356788;
	book[7].isbn  = 7890999243552;
	book[8].isbn  = 8901188826666;
	book[9].isbn  = 9012224563728;
	book[10].isbn = 0012312222112;
	book[11].isbn = 0112344882773;
	book[12].isbn = 0122309412036;
	book[13].isbn = 0132300098765;
	book[14].isbn = 0142333387887;
	book[15].isbn = 0152322229999;
	book[16].isbn = 0162322222000;
	book[17].isbn = 0172311993873;
	book[18].isbn = 0182333333221;
	book[19].isbn = 0192300000000;
	book[20].isbn = 0;

	count=20;
}

.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.