Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:06:03+00:00 2026-06-16T06:06:03+00:00

I’m trying to do a search Method in which checks 2 IDs which only

  • 0

I’m trying to do a search Method in which checks 2 IDs which only store integer.

Firstly I have a database of customers. I input the Name,Surname,ID and Address after each other in this order and then these are immediately saved into the file

When the User inputs the ID card this calls this Search Method and checks through all the file to see whether the ID is unique or not. If it is not, then it returns 0 otherwise it returns 1

Now the problem is this.
When I am inputting the ID, whether it is unique or not it keeps on going, but then when it outputs what I wrote it, for the NAME and SURNAME it shows only the first record I have stored there (like stuck in some kind of buffer), the ID and the address outputs normally.

The File is Also NOT Updated meaning, the save file did not occur.
Now when I Remove this method, the appending works normally, but I won’t have access to the comparing of IDs.

Any suggestions why this is happening? and if possible any idea how I can fix it?
it’s like whenever I’m doing this search method the whole file is getting started from the beginning and getting stuck there. I Tried using the method with boolean but still no avail. When I tried using it with Boolean instead of the line “if (customerID(scanf (“%d”,&cCheck)) == 1)” I made it == TRUE, it was giving me an error that the output will
always be == FALSE because the data is not NULL.

and oh TRUE and FALSE are valid in my case as I have a typedef enum boolean in the common.h

The code is as follows [posting the whole file]:
The methods concerned are [ void addCustomer()] and [int customerID (int cCheck)
but I posted all as some of them are interconnecting.

EDIT!!! – The ID even if they are NOT unique, it is still Accepted…

/*
 * CustomerMainMenu.c
 * Author: DodoSerebro
 *
 * This class will output the Customer's Main Menu and re-directs to the
 * corresponding section
 *
 */
#include<io.h>
#include<fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "..\Headers\common.h"
#include "..\Headers\customerManagement.h"

static FILE *cfp;
static customer c;
#define STRUCTSIZE sizeof (customer)


/** This is the Customers's Main Menu in which the various sections can be
 *  accessed from here
 */
boolean  customerMainMenu()
{



    int optionC;
    clrscr();

    copyright();


    printf ("\n\n\n\n\t\t    ************* Customer's Main Menu *************\n \n \n");

    printf ("Press [1] to add a new Customer\n");
    printf ("Press [2] to edit a Customer\n");
    printf ("Press [3] to list all Customers\n");
    printf ("Press [4] to Show a Customer's last Order\n");
    printf ("Press [5] to go back to Main Menu\n\n\n");


    if (scanf ("%d",&optionC) == 1)
    {
        switch (optionC)
        {

        case 1:
        {
            clrscr();
            getchar();
            addCustomer();
            break;
        }
        case 2:
        {
            printf ("Edit a Customer\n");
            break;
        }

        case 3:
        {
            clrscr();
            listCustomers();
            system ("PAUSE");
            break;
        }
        case 4:
        {
            printf ("Customer's Last Order\n");
            break;
        }
        case 5:
        {
            system ("PAUSE");
            break;
        }
        default:
        {
            if (optionC != 1 || optionC != 2 || optionC != 3 || optionC != 4 || optionC !=5)
            {
                clrscr();
                printf ("Invalid option!\n");
                system ("PAUSE");
                customerMainMenu();
            }
            break;
        }
        }
    }
    return TRUE;

}

/**
 *  This following method will append a customer to the
 *  database at the end of the file
 *
 *  */

void addCustomer ()
{
    char ch;
    copyright();

    printf ("\n\n\n\n\t\t    ************* Add Client **********\n \n \n");

    if ((cfp = fopen ("customers.dat","a+b")) == NULL)
    {
        fputs("Can't open customers.dat file\n",stderr);
    }



    printf ("\tThis will add another customer to the the database\n");
    printf ("\tPress 'Y' to confirm or 'N' to return to the Client Main Menu\n\tWITHOUT adding a customer\n");
    ch = getchar();

    if (ch == 'n' || ch == 'N')
    {
        customerMainMenu();
    }
    else if (ch == 'y' || ch == 'Y')
    {
        fflush(stdin);
        clrscr();
        printf ("\n\n\n\n\t\t    ************* Add Client **********\n \n \n");
        printf ("Please enter Name:\n");
        while (scanf ("%s", c.name) == 0 || cCheck(c.name,100) == FALSE);
        {

        }


        printf ("Please Enter Surname: \n");
        while (scanf ("%s",c.surname) == 0 && cCheck (c.surname,100) == FALSE);
        {

        }
        printf ("Please Enter ID Card, [NOTE! Only numbers are allowed!]\n");
        int cCheck;
        if (customerID(scanf ("%d",&cCheck)) == 1)
        {
            printf ("ID already Taken, Client exists!\n");
            printf ("Do you want to enter another ID? 'Y' for Yes and 'N' to return to Main Menu\n");
            ch = getchar();
            if (ch == 'Y' || ch == 'y')
            {
                scanf ("%d",&cCheck);
                customerID(cCheck);
                c.ID = cCheck;
            }
            else
            {
                customerMainMenu();
            }
        }
        else
        {
            c.ID = cCheck;
        }


        getchar();

        printf ("Please Enter Address:\n");
        gets(c.address);


        fwrite (&c,STRUCTSIZE, 1, cfp);

        printf ("For Testing purposes:\n");
        printf (" %s\n %s\n %s\n %d\n", c.name, c.surname, c.address, c.ID);
        askAnother();


    }
    else
    {
        printf ("\nInvalid choice! Either Y or N is accepted\n");
        system ("PAUSE");
        getchar();
        clrscr();
        addCustomer();
    }
}

void listCustomers()
{

    if ((cfp = fopen ("customers.dat","rb")) == NULL)
    {
        fputs("Can't open customers.dat file\n",stderr);
        printf ("Returning to Customer Main Menu");
        system ("PAUSE");
        customerMainMenu();
    }

    rewind (cfp);
    while (fread (&c,STRUCTSIZE,1,cfp)==1)
    {
        printf ("Customer: %s %s ID: %d\n", c.surname, c.name, c.ID);
    }
    fclose (cfp);


}


void askAnother()
{
    printf ("Do you want to add another Customer?\n");
    printf ("Enter 'Y' for yes and 'N' to return to the Main Menu\n");

    char input;
    input = getchar();

    if (input == 'Y' || input == 'y')
    {
        getchar();
        addCustomer();
    }
    else if (input == 'N'|| input == 'n')
    {

        fclose (cfp);
        customerMainMenu();

    }
    else
    {

        printf ("Invalid Option! Only Y or N are allowed\n");
        system ("PAUSE");
        clrscr();
        askAnother();

    }

}


boolean cCheck(char *test, int max)
{
    int x;
    for (x =0; x<max; x++)
    {
        if (isdigit(test[x]))
        {
            return FALSE;
        }
        if (x==max)
        {
            return TRUE;
        }
        x++;

    }
    return TRUE;
}

/**
 *  This method will compare the ID passed from the ID of the customer to check
 *  whether it is exists or not. If it exists it will output 1 otherwise it
 *  will output -1. This will make sure that the Person's ID is unique
 *
 */


int customerID (int cCheck)
{

    rewind (cfp);
    while (fread (&c,STRUCTSIZE,1,cfp)==1)
    {
        if (c.ID == cCheck)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    return 1;
}

EDIT!!

Uploading Image to show what I mean if I’m not clear

(Notice how the name and surname differ from those Input)
!http://s017.radikal.ru/i443/1212/c8/1ea9bc56d980.jpg

The following shows what I have in the file
(only one file)
!http://s017.radikal.ru/i431/1212/49/2a0df6acf9ec.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:06:04+00:00Added an answer on June 16, 2026 at 6:06 am
    if (customerID(scanf ("%d",&cCheck)) == 1)
    

    Here, you are the return value of scanf() to function customerID() whereas you actually wanted to pass the scanned value cCheck.

    You can separate the call to function and input reading as below:

       if(scanf ("%d",&cCheck) != 1) {
       // Input error handling
       }
       else if (customerID(cCheck) == 1) {
        ...
    

    Another issue is, you have a function named cCheck and you also have a local variable named cCheck. Rename one of them appropriately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.