944,117 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2113
  • C RSS
Aug 23rd, 2006
0

help me pls!!!some of my functions doesn't work!

Expand Post »
  1. #include<alloc.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<conio.h>
  5. #include<dos.h>
  6. #include<ctype.h>
  7.  
  8. typedef struct node
  9. {
  10. int dd,mm,yy;
  11. int cus_ac_no[15];
  12. char cus_name[25],cus_add[45],cus_ph_no[17];
  13. double cus_bal;
  14. float cus_intrst;
  15. struct node *next;
  16. }node;
  17. node *L,*ptr;
  18.  
  19.  
  20. void add()
  21. {
  22. node *p,*q,*new;
  23. p=q=L;
  24. clrscr();
  25. new=(node*)malloc(sizeof(node));
  26. if(new==NULL)
  27. {
  28. printf("list is full");
  29. getch();
  30. return;
  31. }
  32. else {
  33. printf(" Enter customer account number : ");
  34. scanf("%d",new->cus_ac_no);
  35. printf(" Enter customer name : ");
  36. gets(new->cus_name);
  37. printf(" Enter customer address : ");
  38. gets(new->cus_add);
  39. printf(" Enter customer phone number :");
  40. gets(new->cus_ph_no);
  41. printf(" Enter the amount you want deposit :");
  42. scanf("%lf",&new->cus_bal);
  43. while(new->cus_ac_no > p->cus_ac_no && p!=NULL)
  44. {
  45. q=p;
  46. p=p->next;
  47. }
  48. if(L!=NULL){
  49. q->next=new;
  50. new->next=p;
  51. }
  52. else{
  53. L=new;
  54. new->next=p;
  55. }
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62. void list()
  63. {
  64. node *ptr;
  65. ptr=L;
  66. while(ptr!=NULL);
  67. {
  68. gotoxy(8,2); printf("============================================\n");
  69. gotoxy(8,3); printf("......Customer's Information .......");
  70. gotoxy(8,4); printf("============================================\n");
  71. gotoxy(7,7); printf("|-> Customer Account number is: %d",ptr->cus_ac_no);
  72. gotoxy(7,10); printf("|-> Customer Name is: %s",ptr->cus_name);
  73. gotoxy(7,13); printf("|-> Customer Address is: %s",ptr->cus_add);
  74. gotoxy(7,16); printf("|->Customer Phone number is: %s",ptr->cus_ph_no);
  75. gotoxy(7,19); printf("|-> Customer Balence is : %.3lf ",ptr->cus_bal);
  76. gotoxy(7,22); printf("|->Account opened on :");
  77. gotoxy(7,24); printf("<-->Press any key to continue");
  78. ptr=ptr->next;
  79. } getch();
  80. }
  81. void transac()
  82. {
  83. printf("trans..");
  84. getch();
  85. }
  86.  
  87. void del(int cus_ac_no)
  88. {
  89. node *p,*q;
  90. p=q=L;
  91. while(cus_ac_no!=p->cus_ac_no && p!=NULL)
  92. {
  93. q=p;
  94. p=p->next;
  95. }
  96. if(p==NULL){
  97. printf("record not found");
  98. getch();
  99. return;
  100. }
  101. else{
  102. if(L==p)
  103. L=p->next;
  104. else
  105. q->next=p->next;
  106. free(p);
  107. }
  108. }
  109.  
  110. int menu()
  111. { int i,s=0;
  112. do{
  113. clrscr();
  114. gotoxy(4,9); printf("1.-> Adding a new Account\n");
  115. gotoxy(4,12); printf("2.-> List all Accounts\n");
  116. gotoxy(4,15); printf("3.-> Transaction [Deposit/Withdraw]\n");
  117. gotoxy(4,18); printf("4.-> Delete any \n");
  118. gotoxy(4,21); printf("5.-> Exit \n");
  119. gotoxy(4,29); printf("Enter your choice [1-5] :");
  120. scanf("%d",&s);
  121. }while(s<1 && s>5);
  122. return(s);
  123. }
  124.  
  125.  
  126.  
  127.  
  128. main()
  129. {
  130. int i;
  131. int cus_ac_no[15];
  132. while(1){
  133. i=menu();
  134. switch(i)
  135. {
  136. case 1 :
  137. clrscr();
  138. add();
  139. break;
  140.  
  141. case 2:
  142. clrscr();
  143. list();
  144. break;
  145.  
  146. case 3:
  147. clrscr();
  148. transac();
  149. break;
  150.  
  151. case 4 :
  152. clrscr();
  153. printf("enter accnt no. that u want 2 erase:");
  154. scanf("%d",cus_ac_no);
  155. for(i=0;i<45;i++);
  156. while(cus_ac_no[i] > '0 ' && cus_ac_no[i] <'9')
  157. cus_ac_no[i]=cus_ac_no[i];
  158. del(cus_ac_no[45]);
  159. break;
  160.  
  161.  
  162. case 5:
  163. clrscr();
  164. printf("THANK YOU FOR USING THIS SOFTWARE");
  165. getch();
  166. exit(0);
  167. break;
  168.  
  169.  
  170. default :
  171. clrscr();
  172. gotoxy(5,3); printf(" SORRY WRONG CHOICE....");
  173. gotoxy(5,5); printf(" PRESS ANY KEY TO CONTINUE....");
  174. getch();
  175. break;
  176.  
  177. }
  178. }
  179. }
Similar Threads
Reputation Points: 14
Solved Threads: 0
Light Poster
comp_sci11 is offline Offline
38 posts
since Jul 2006
Aug 23rd, 2006
0

Re: help me pls!!!some of my functions doesn't work!

What is the problem? We don't have the time to run and debug your program. Narrow down the function that is wrong and post it. Post properly formatted code.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Aug 23rd, 2006
0

Re: help me pls!!!some of my functions doesn't work!

help!! my program is running but when i choose 2 which is the list function that display all the info. inputted by the user, it doesn't display at all!! and when i'm adding an account it is getting the acount number first and it will skip in getting the customer name and proceed to customer address.
Can someone help me?? pls..
And another problem,when i'm inputting a letter or words in the menu
it doesn't goes back again to accept another choice.unlike when i'm inputting a number greater than and less than my choices(1-5) it goes back again to accept another choice!can someone helpme pls!! I REALLY NEED TO RUN THIS PROGRAM!!
Reputation Points: 14
Solved Threads: 0
Light Poster
comp_sci11 is offline Offline
38 posts
since Jul 2006
Aug 23rd, 2006
1

Re: help me pls!!!some of my functions doesn't work!

It might sound harsh, but we're (at least, Me) are not interested in how urgent this is for you.

Next time you post please use proper English, punctuation etcetera. Also choosing a proper title would help a lot. The title you used doesn't give any information at all. You're not giving any information about what the problem is.

The only thing you do is giving us a piece of code, without even telling what's wrong, and then expecting us to locate the problem and solve it.

I know it might not be your fault that your English isn't perfect, but I think punctuation is the same in all languages (Okay, most of the languages).

Don't think I'm mad at you, or dislike you. It's just several things that need to be corrected before you should expect to receive any usefull input from us.

I'll give you just an example to show how confusing it can be to read something without punctuation:

Quote ...
it doesn't goes back again to accept another choice.unlike when i'm inputting a number greater than and less than my choices(1-5) it goes back again to accept another choice
Now please re-read this sentence, and see if you can figure out what you mean with that. I can't really. I have no clue what you're trying to say in that sentence.


Yours,
Eddy
Reputation Points: 38
Solved Threads: 3
Junior Poster in Training
Eddy Dean is offline Offline
56 posts
since Jul 2006
Aug 23rd, 2006
0

Re: help me pls!!!some of my functions doesn't work!

Click to Expand / Collapse  Quote originally posted by comp_sci11 ...
#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.
Last edited by ~s.o.s~; Aug 23rd, 2006 at 1:56 pm.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Aug 23rd, 2006
0

Re: help me pls!!!some of my functions doesn't work!

> new is a keyword which cant be used as a variable
True, but this is C, so it's OK.

There's some good stuff in there ~s.o.s~

Here's some more for the OP to think about.

> while(new->cus_ac_no > p->cus_ac_no
You're comparing two pointers here, not two values.
In general, you seem very confused as to what the customer account number is supposed to be. In places, it's an integer, and in other places, you seem to be trying to treat it as a string.

> while(ptr!=NULL);
That ; at the end is one place where your code can lock up.
If ptr is not NULL when it enters the loop, then that is where it will stay, because the loop body ( just that ; ) can't change the value of ptr.
The body of code which follows, which seems like it should be part of the while loop isn't part of the loop at all.

> for(i=0;i<45;i++);
This is another useless loop, which is just the same as saying
i = 45;

> while(cus_ac_no[i] > '0 ' && cus_ac_no[i] <'9')
i is now 45, but your array is only 15 elements. You're in no man's land doing who knows what to someone elses memory.
> cus_ac_no[i]=cus_ac_no[i];
This isn't going to change i either, so if the while loop starts off being true, then this is where it will stay, forever assigning cus_ac_no[45] = cus_ac_no[45];

> del(cus_ac_no[45]);
More out of range access on the array with only 15 elements.

> scanf("%d",cus_ac_no);
If it were %s, and cus_ac_no were a char array (not an int array), this might make a bit of sense with the for loop which follows.

> clrscr(); and gotoxy(5,3);
You should remove ALL these until the program is working properly.
Until then, it's just clutter for everyone else to look at, and severely restricts people from trying your code for themselves.
When it's all working, adding them all in again won't take that long, as it's just tidying up the presentation, it's not going to affect the core functions at all.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Problem in String Search:Please Help
Next Thread in C Forum Timeline: File handling





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC