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

struct account {
    char AccName[20];
    int Age;
    double AccBalance;
    struct account *Next;
};

typedef struct account BankAcc;

void init( struct Account **headOfList );
void insert(struct account **headOfList, char *name, int age, double balance);
int Delete(struct account **headOfList, char *name );
void print(struct account *headOfList );



void main() {
    BankAcc *startPtr = NULL;

    int selection;
    printf("Enter selection and following below: \n");
    printf("1. Insert Account \n2. Delete Account \n3. Print All \n");
    printf("Enter your selection : ");
    scanf("%d",&selection);

    while(selection != 5) {
        switch(selection) {
            case 1:
                char *Username;
                char TmpName[20];
                int UserAge;
                double UserBalance;



                // Enter Account Name
                printf("Enter Account Name : ");
                scanf("%s",&TmpName);
                Username = TmpName;
                // Enter Age
                printf("Enter Age : ");
                scanf("%d",&UserAge);
                // Enter Account Balance
                printf("Enter Account Balance :  ");
                scanf("%d",&UserBalance);

                insert(&startPtr,Username,UserAge,UserBalance);
            break;

            case 2:
                char *del;
                char tmpdelete[20];

                printf("Enter Account Name : ");
                scanf("%s",&tmpdelete);
                del = tmpdelete;
                Delete(&startPtr,del);
            break;

            case 3:
                print(startPtr);
            break;

        }

        printf("---------------------------------------------------------\n");
        printf("Enter selection and following below: \n");
        printf("1. Insert Account \n2. Delete Account \n3. Print All\n");
        printf("Enter your selection : ");
        scanf("%d",&selection);
    }

}
void init( struct Account **headOfList ){

}

void insert(struct account **headOfList, char *name, int age, double balance) {
    struct account *newPtr;
    struct account *previousPtr;
    struct account *currentPtr;

    newPtr = (account*) malloc(sizeof(account));

    if(newPtr != NULL) {

        //newPtr->AccName = (char *)malloc(40 * sizeof(char));
        strcpy (newPtr->AccName,name);

        newPtr->Age = age;
        newPtr->AccBalance = balance;
        newPtr->Next = NULL;


        previousPtr = NULL;
        currentPtr = *headOfList;



        while(currentPtr != NULL && balance < currentPtr->AccBalance) {
            previousPtr = currentPtr;
            currentPtr = currentPtr->Next;
        }

        if(previousPtr == NULL) {
            newPtr->Next = *headOfList;
            *headOfList = newPtr;
        } else {
            previousPtr->Next = newPtr;
            newPtr->Next = currentPtr;
        }
    }

    //printf("%s\n",headOfList->AccName);

}


int Delete(struct account **headOfList, char *name ){



    char mm[20];
    strcpy (mm,name);
    printf("%s\n",mm);

    char m2[20];
    strcpy (m2,(*headOfList)->AccName);
    printf("%s\n",m2);
    //printf("%s\n",(*headOfList)->AccName);

    while (strcmp (mm,m2)!=0);
    printf("Valid\n");

    return 0;
}

void print(struct account *headOfList ) {
    if(headOfList == NULL) {
        printf("List is empty. \n");
    } else {
        printf("Account Name Age Account Balance\n");
        printf("_________________________________________________\n");

        while(headOfList != NULL) {
            printf("%s\t%d\t%d\n",headOfList->AccName,headOfList->Age,headOfList->AccBalance);
            headOfList = headOfList->Next;
        }
    }
}

Hi, here in your Delete Function, you don't have code for delete a account, you only compares 2 "Account Names".

int Delete(struct account **headOfList, char *name ){
char mm[20];
 strcpy (mm,name);
 printf("%s\n",mm);
 char m2[20];
 strcpy (m2,(*headOfList)->AccName);
 printf("%s\n",m2);
 //printf("%s\n",(*headOfList)->AccName);
 while (strcmp (mm,m2)!=0);
 printf("Valid\n");
 return 0;
 }
This article has been dead for over six months. Start a new discussion instead.