Here is my code....

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


struct data{
    int CustomerID;
    char Forename[15];
    char Surname[20];
};


void CreateID ();
//int checksize();
//void check number();

void CreateFirst ();
int checklen();
int checknum();


void CreateLast();
int checklength();
//int checknumber();

void ViewRecord();


int main()
{
    struct data records[2000];
    char selection = 0;
    int add =0;


        do{
            printf("\n Please choose from:\n");
            printf("\n 1. To create a new record enter: 'c'");
            printf("\n 2. To view a record enter: 'v'");
            printf("\n 3. To exit the program enter: 'x'\n");

            scanf("%c", &selection);


                if(selection == '\n')
                {
                    scanf("%c", &selection);
                }

                    switch(selection)
                    {
                        case 'c':printf("New Record");

                        CreateID(add,records);
                        CreateFirst(add,records);
                        CreateLast(add,records);
                        add++;
                        break;

                        case 'v':printf("View Record");
                        ViewRecord(add,records);
                        break;

                        case 'x':printf("Exit Program");
                        break;

                        default:printf("Incorrect entry");
                        break;
                    }

                        }while(selection != 'x');
                                return 0;
}


void CreateID(int add, struct data *records)
{

    printf("\nEnter the following details\n");
    printf("\nCustomer ID:");
    scanf("%d", &records[add].CustomerID);

}



void CreateFirst(int add, struct data *records)
{
    int x = 1;
    int y ;

    while(x == 1)
        {
        printf("\nForename:");
        scanf("%s", records[add].Forename);

        x = checklen(add,records);
        }

         if(y == 1)
        {
        y = checknum(add,records);

        }

}




int checklen(int add, struct data *records)

{
   int len;
        len = strlen(records[add].Forename);
            if (len > 14)
            {
                printf("Too many characters");
                return 1;
            }
            return 0;
}



int checknum (int add, struct data *records)
{
            int i;

                for(i=0;i<add;i++)
                {
                 if(isdigit(records[add].Forename)==1)
                  printf("\nInvalid\n");


                }
                return 0;
}





void CreateLast(int add, struct data *records)

{
    int x = 1;

    while(x == 1)
        {

        printf("\nSurname:");
        scanf("%s", records[add].Surname);
       x= checklength(add,records);

    }

}

int checklength(int add, struct data *records)

{
   int len;
        len = strlen(records[add].Surname);
            if (len > 19)
            {
                printf("Too many characters");
                return 1;
            }
            return 0;
}



void ViewRecord(int add, struct data *records)
{
            int i;
                for(i=0;i<add;i++)
                {

                    printf("\nCustomer ID: %d", records[i].CustomerID);
                    printf("\nForename: %s", records[i].Forename);
                    printf("\nSurname: %s\n", records[i].Surname);
                }
}

Recommended Answers

All 4 Replies

What is not working?

Member Avatar for iamthwee

in line 133 isdigit is checking the forename. Are you expecting that to be a digit?

With this code, i have 3 options to start off with. After you choose the 'c' option you can enter the customer ID, forename and surename. after those are entered you can view them. However with the forename, i need it where you cant enter more than 15 characters(THIS WORKS IN MY CODE) and secondly while entering my forename i want it so if you enter a number there will be an error message appear, so you can only enter a 15 character name with no numbers.

Sorry, ive changed isdigit to isalpha

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.