can you help me with delete?

I really need to finish this ASAP but with all the codes running in my head i can't think properly, I've got more system to make for finals and this one's just the 1st I hope you can help me.

i wanna ask help about delete where in when i delete empnumber the remaining emp number will go to that number for example:

I have 3 employee records


Employee records:
1 lei ren F
2 wen lei R
3 lou wuo T

: I want to delete number 2

1 lei ren F
( Deleted empoyee record Number 2)
3 lou wuo T

:now employee number 2 was delete, Instead of 2 being deleted I want number 3 to go to number 2 when deleted like so

1 lei ren F
2 lou wuo T (the previous employee records(which was employee number 2) that was deleted will be replaced by the next number 3 and the number 3 will become 2)

-------------------------------------------------
:in this code that I was able to make is if I delete employee number 2. it would look like this
1 lei ren F
( Deleted empoyee record Number 2)
3 lou wuo T

:so if i Add another entry and lets say I will use 2 again it will look like this
1 lei ren F
3 lou wuo T
2 wen lei R

-------------------------------------------------------------
here is the codes:

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

struct info {
int empno;
char lname[255];
char fname[255];
char mid[255];
};

void search(int employeeNumber);

struct info emp[50];
int choice=0, selection=0, i,j, tempnumber, existing=0, empindex;

main(){

while(selection!=5){
system("cls");
gotoxy(10,1);
existing=0;
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" Employee Records ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\n[1]Data Entry\n[2]View Record\n[3]Update\n[4]Search\n[5]Exit\n[6]Delete All\n[7]Delete One\n\nSelect Transaction: ");
scanf("%d", &selection);
clrscr();


if(selection==1){
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" ADD EMPLOYEE ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEnter Employee Number: ");
scanf("%d",&tempnumber);

search(tempnumber);

if(existing==0){
emp[choice].empno=tempnumber;
printf("Enter Employee Last Name: ");
scanf("%s",&emp[choice].lname);
printf("Enter Employee First Name: ");
scanf("%s",&emp[choice].fname);
printf("Enter Employee Mi: ");
scanf("%s",&emp[choice].mid);
choice++;
clrscr();
}

else{
printf("\nEmployee number already exists");
getch();
clrscr();

}
}

else if (selection==2) {
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" Employee Records ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEMPLOYEE NUMBER\t\tLAST NAME\tFIRST NAME\tMIDDLE INITIAL\n");
for(i=0;i<choice;i++) {
printf("\n%d", emp[i].empno);
printf("\t\t\t%s", emp[i].lname);
printf("\t%s", emp[i].fname);
printf("\t\t%s", emp[i].mid);

}
getch();
clrscr();
}

////////////////////////

else if (selection==6) {
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" Delete All Employee Record ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEMPLOYEE NUMBER\t\tLAST NAME\tFIRST NAME\tMIDDLE INITIAL\n");
for(i=0;i<choice;i++) {
choice--;
clrscr();
}
getch();
clrscr();
}




////////////////////


if(selection==7){
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" Delete EMPLOYEE ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEnter Employee Number: ");
scanf("%d",&tempnumber);

// search(tempnumber);
for(i=0;i<choice;i++){
if(emp[1].empno==tempnumber)
{
for(j=1;j<choice-2;j++)
{
emp[j].empno = emp[j+1].empno;
}
choice--;


}
}
}
///////////////////

else if (selection==3){
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" UPDATE EMPLOYEE ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEnter employee number to edit: ");
scanf("%d",&tempnumber);
search(tempnumber);
if(existing==1){
clrscr();

printf("\nEMPLOYEE NUMBER\t\tLAST NAME\tFIRST NAME\tMIDDLE INITIAL\n");
printf("\n%d", emp[empindex].empno);
printf("\t\t\t%s", emp[empindex].lname);
printf("\t\t%s", emp[empindex].fname);
printf("\t\t%s\n", emp[empindex].mid);

printf("\nEnter Employee's Last Name: ");
scanf("%s",&emp[empindex].lname);
printf("\nEnter Employee's First Name: ");
scanf("%s",&emp[empindex].fname);
printf("\nEnter Employee's Mi: ");
scanf("%s",&emp[empindex].mid);
clrscr();
}
else{
printf("\nEmployee No. Does not Exist");
getch();
clrscr();
}
}

else if (selection==4){
system("cls");
gotoxy(10,1);
printf("------------------------------------------------------------");
gotoxy(10,2);
printf(" SEARCH EMPLOYEE ");
gotoxy(10,3);
printf("------------------------------------------------------------");
printf("\nEnter the employee number to view: ");
scanf("%d",&tempnumber);
search(tempnumber);
if(existing==1){
printf("\n\nEmployee Number: %d", emp[empindex].empno);
printf("\nEmployee Last Name: %s", emp[empindex].lname);
printf("\nEmployee First Name: %s", emp[empindex].fname);
printf("\nEmployee Mi: %s\n", emp[empindex].mid);

printf("\nEMPLOYEE NUMBER\t\tLAST NAME\tFIRST NAME\tMIDDLE INITIAL\n");
printf("\n%d", emp[empindex].empno);
printf("\t\t\t%s", emp[empindex].lname);
printf("\t\t%s", emp[empindex].fname);
printf("\t\t%s\n", emp[empindex].mid);

}
else{
printf("\nEmployee No. Does not Exist");
}
getch();
clrscr();
}


}
}

void search(int employeeNumber){
for(i=0;i<=choice;i++) {
if(tempnumber==emp[i].empno){
existing=1;
empindex=i;
}
}
}

Topic archived. No new replies allowed.