#include<alloc.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<dos.h>
#include<ctype.h>
typedef struct node
{
int dd,mm,yy;
int cus_ac_no[15];
char cus_name[25],cus_add[45],cus_ph_no[17];
double cus_bal;
float cus_intrst;
struct node *next;
}node;
node *L,*ptr;
void add()
{
node *p,*q,*new;
// new is a keyword which cant be used as a
//varible . better choose a new name
p=q=L;
clrscr();
new=(node*)malloc(sizeof(node));
if(new==NULL)
{
printf("list is full");
getch();
return;
}
else {
printf(" Enter customer account number : ");
scanf("%d",new->cus_ac_no);
printf(" Enter customer name : ");
gets(new->cus_name);
printf(" Enter customer address : ");
gets(new->cus_add);
printf(" Enter customer phone number :");
gets(new->cus_ph_no);
printf(" Enter the amount you want deposit :");
scanf("%lf",&new->cus_bal);
while(new->cus_ac_no > p->cus_ac_no && p!=NULL)
{
q=p;
p=p->next;
}
if(L!=NULL){
q->next=new;
new->next=p;
}
else{
L=new;
new->next=p;
}
}
}
void list()
{
node *ptr;
ptr=L;
while(ptr!=NULL);
{
gotoxy(8,2); printf("============================================\n");
gotoxy(8,3); printf("......Customer's Information .......");
gotoxy(8,4); printf("============================================\n");
gotoxy(7,7); printf("|-> Customer Account number is: %d",ptr->cus_ac_no);
gotoxy(7,10); printf("|-> Customer Name is: %s",ptr->cus_name);
gotoxy(7,13); printf("|-> Customer Address is: %s",ptr->cus_add);
gotoxy(7,16); printf("|->Customer Phone number is: %s",ptr->cus_ph_no);
gotoxy(7,19); printf("|-> Customer Balence is : %.3lf ",ptr->cus_bal);
gotoxy(7,22); printf("|->Account opened on :");
gotoxy(7,24); printf("<-->Press any key to continue");
ptr=ptr->next;
} getch();
}
void transac()
{
printf("trans..");
getch();
}
void del(int cus_ac_no)
{
node *p,*q;
p=q=L;
// here cus_ac_no member of struct which is actually a array of
// integer is compared with a integer value which is cus_acc_no which // accounts to the comparision of an int with pointer type ?
while(cus_ac_no!=p->cus_ac_no && p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL){
printf("record not found");
getch();
return;
}
else{
if(L==p)
L=p->next;
else
q->next=p->next;
free(p);
}
}
int menu()
{ int i,s=0;
do{
clrscr();
gotoxy(4,9); printf("1.-> Adding a new Account\n");
gotoxy(4,12); printf("2.-> List all Accounts\n");
gotoxy(4,15); printf("3.-> Transaction [Deposit/Withdraw]\n");
gotoxy(4,18); printf("4.-> Delete any \n");
gotoxy(4,21); printf("5.-> Exit \n");
gotoxy(4,29); printf("Enter your choice [1-5] :");
scanf("%d",&s);
}while(s<1 && s>5);
return(s);
}
main()
{
int i;
int cus_ac_no[15];
while(1){
i=menu();
switch(i)
{
case 1 :
clrscr();
add();
break;
case 2:
clrscr();
list();
break;
case 3:
clrscr();
transac();
break;
case 4 :
clrscr();
printf("enter accnt no. that u want 2 erase:");
scanf("%d",cus_ac_no);
for(i=0;i<45;i++);
// dont put quotes around the literals since now they will be treated
// as characters and you actuallly want to compare integer values.
while(cus_ac_no[i] > '0 ' && cus_ac_no[i] <'9')
cus_ac_no[i]=cus_ac_no[i];
del(cus_ac_no[45]);
break;
case 5:
clrscr();
printf("THANK YOU FOR USING THIS SOFTWARE");
getch();
exit(0);
break;
default :
clrscr();
gotoxy(5,3); printf(" SORRY WRONG CHOICE....");
gotoxy(5,5); printf(" PRESS ANY KEY TO CONTINUE....");
getch();
break;
}
}
}
Actually too many problems with your code.
I would list some of them and expect you to correct them to get any further help from our side. The problem areas in your code are marked as red.
1. Dont ever use
gotoxy () ever. I think that you are probably usign Turbo C++ compiler so better dump it and get a new compiler, the link of which is mentioned in one of the stickes. Using
gotoxy () kills program portability and you is considered as bad programming practice.
2. The same goes with
getch () . Using it to make your program wait for input is bad since it is a non standard function. Better use
getchar () which performs the same function and is a portable one.
3. Why do you need to keep the
cust_acc_no in your structure to be an array of 15 ints. Cant it just be an int to hold the value of account number of a single customer ?
4. Using
gets after
scanf is the worst mistake you can afford to do since the
newline character ('\n') left after [inlinecode] scanf [inlinecode] would be accepted by
gets as a valid input thereby making the program not wait for the customer name input and always keeping the customer name as a newline character. Better use
fgets (char*, size_t inputsize, filestream ) to get all the inputs from user. THe bottom line is either use
fgets () or
scanf () throughout your code and try not to intermingle them.
5. The same advice of portability goes for
clrscr () as it is non standard function. dont use it.
Hope you make the following changes and present the code in a more appealign manner which will make it easier for us to find errors for you.
Hope it helped, bye.