0

我想在程序中输入一个名称,该名称将作为文件的关键字。该程序将在文件中搜索该名称并显示与其相关的所有其他信息。下面是代码片段。

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


FILE *ptr;
int bookgenre;
char fname[20], lname[20],book[20],gender[20];
struct persfile{
    char fname[20];
    char lname[20];
    char bookname[20];
    int  date, latefees;
    char gender;
};
void menu ();
void caseCheck(int);

int main(void)
{
    int New = 0, genrenum = 0, count=0;
    struct persfile personfile[count]; //Intialization of the struct in the main function
    menu();

    /*New = getch();*/
    scanf("%d",&New);
        system ("cls");

        if(New == 2)
        {
         for (count=1; count<=200; count++ )
         {

            int latefees=0;
            ptr = fopen("membersit.txt", "a");

             /*for (count=1;count<=5;count++)*/


            printf("Enter the first name of the person \n");
            scanf("%s", personfile[count].fname);
            printf("Enter the last name of the person \n\n");
            scanf("%s", personfile[count].lname);
            printf("Enter the gender of the individual....(M/F) \n");
            personfile[count].gender = getch();
            printf("%c", personfile[count].gender);
                                                            // At a later date...examine the time library and look at its connection to the
            system("cls");                                          //date at which the book was rented.. //

            printf("The code for the differnt book genres are given below\n\n");
            printf("000-Kids...111-Supernatural...222-Gaming\n\n");
            printf("_____________________\n\n");


            printf("Enter the genre number of said book\n");
            scanf("%d", &genrenum);

            system ("cls");
            printf("These are the books under this genre\n\n");
            printf("______________");
            system("cls");

            caseCheck(genrenum);
            scanf("%s",book);

            printf("Since this is a new individual..he has no outstandng latefees");
            fprintf(ptr,"%s %s %d \n", personfile[count].fname, personfile[count].lname, personfile[count].latefees);
            fclose((ptr));
            system("cls");
         }
        } 

        else if(New==3)
        {

        ptr=fopen("membersit.txt", "r");

        fscanf(ptr,"%s %s",fname,  lname);


        printf("First Name: %s \n Last Name: %s \n  Latefees: %d  \n", fname, lname);

        fclose((ptr));


    /*if (ptr==NULL){
        printf("This file is not in our system");
        exit(0);
     }*/
        }

    /*search the existing files for the name of the person and open up their file
    The opened file would have late fees as a header..*/



system("Pause");
return 0;
};


void menu ()

{
    printf("Welcome to the library!!");
    printf("\n___________________________________________________");
    printf("\n\nWhat would you like to do?\n");
    printf("\n1.Add information to existing member \n\n2.Create a new member");
    printf("\n\n3.Search a member\n\n4.Display all members\n\5.End the program\n\n\n\n");
}

void caseCheck(int genrenum)
{
    switch (genrenum)
    {
        case 000:
            printf("KIDS BOOKS\n_________________________________________\nDora the explorer\nBlues Clues\nGo Diego Go\nThe Little Engine Who Could\n Curious George\n\n");
        break;

        case 111:
            printf("SUPERNATURAL BOOKS\n__________________________________\nLost\nHarry Potter\nAnnie/\n\n");
            break;

        default:
        printf("The data you entered is invalid");
    }
}

/* Notes :
 Good programming practices
 Your '}' should line up when using condition loops
 -> Variables shoul not be started wth a capital letter */

 /*There was something wrong with your while loop.... you did not implement it correctly... Leave off the terminate function for last
4

0 回答 0