Thread: virtual library

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    41

    virtual library (will pay real big $$$ for complete code)

    This is what I have so far. I'm stuck on what to do next. Can't seem to get book entries to save. Think I have to create a link list but not sure how. Also attached is the problem I'm trying to solve.

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


    struct book
    {
    int code;
    char title[20];
    char author[20];
    int pages;
    struct book*next;
    }*head,*work,libry;

    FILE*library;

    main()
    {

    int pick;
    char ans;
    menu:
    library=fopen("library.dat","wb");
    fread(&library,sizeof(struct book),1,library);
    fclose(library);
    system("cls");
    printf ("\t\t\tTusket Municipal Library\n\n\n");
    printf ("\tPlease make a selection...\n\n");
    printf ("\t1.) Enter a book in the inventory\n");
    printf ("\t2.) Delete a book from the inventory\n");
    printf ("\t3.) Search the inventory for a book\n");
    printf ("\t4.) Display the book inventory\n");
    printf ("\t5.) Exit the program\n\n");
    printf ("\tEnter your selection:1,2,3,4 or 5 \n");
    scanf ("%d", &pick);
    while (pick==1)
    {
    system("cls");
    //create list
    head=work=(struct book*)malloc(sizeof(struct book));
    work=head;
    another:
    printf("Enter code:");
    scanf("%d",&libry.code);
    printf("Enter Title:");
    printf("\n");
    gets(libry.title);
    printf("Enter Author:");
    gets(libry.author);
    printf("Enter Number of Pages:");
    scanf("%d",&libry.pages);
    fwrite (&library,sizeof(struct book),1,library);
    choice:
    printf("\n\nDo you want to add another book?:");//answer must not be a capital
    scanf("%s",&ans);
    if(ans=='n')
    {
    work->next=NULL;
    goto menu;
    }
    else
    {
    if(ans=='y')
    {
    work->next=(struct book*)malloc(sizeof(struct book));
    work=work->next;
    goto another;
    }
    else
    {
    if(ans!='n')
    {
    printf("Please Enter y or n");
    printf ("\n\nPress a key to continue...");
    getch();
    goto choice;
    }
    else
    {
    if(ans!='y')
    {
    printf("Please Enter y or n");
    printf ("\n\nPress a key to continue...");
    getch();
    goto choice;
    }
    }
    }
    }
    library=fopen("library.dat","a+b");
    if((library=fopen("library.dat","a+b"))!=NULL)
    {
    fwrite (&library,sizeof(struct book),1,library);
    fclose (library);
    }

    }
    while (pick==2)
    {
    printf("Not working yet!!!!!");
    printf ("\n\nPress a key to continue...");
    getch();
    goto menu;
    }
    while (pick==3)
    {
    printf("Not working yet!!!!!");
    printf ("\n\nPress a key to continue...");
    getch();
    goto menu;
    }
    while(pick==4)
    {
    printf("Not working yet!!!!!");
    printf ("\n\nPress a key to continue...");
    getch();
    goto menu;
    }
    while(pick==5)
    {
    fclose(library);
    return 0;
    }
    return 0;
    }

    If you send me a working version of this program and you want to collect: send mailing address and the checks in the mail!
    Last edited by spentdome; 04-17-2002 at 12:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2009, 09:25 AM
  2. Replies: 9
    Last Post: 06-18-2009, 04:58 AM
  3. Platform game gravity problem
    By Akkernight in forum Game Programming
    Replies: 33
    Last Post: 02-22-2009, 01:10 PM
  4. Virtual Keyword
    By Shal in forum C++ Programming
    Replies: 6
    Last Post: 05-18-2006, 11:37 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM