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);
}
}