Hijack thread start: shifting a double

This is a discussion on Hijack thread start: shifting a double within the C Programming forums, part of the General Programming Boards category; hello, it is a book database i have made 3 functions out of 5 plz help me these functions are ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    Hijack thread start: shifting a double

    hello,
    it is a book database i have made 3 functions out of 5 plz help me
    these functions are not giving right output .plz plz plz help.
    i wil be highly thankful to him/her.plz
    Code:
    
    
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    
    struct data
    {
    int book_id;
    char authername[89];
    char bookname[80];
    float price;
    };
    struct data book[40];
    void menu(void);
    void add(void);
    void sort(void);
      void _display(void);
    //void bookdetails(void);
    int new;
    main()
    {
     char ch;
     while(1)
    {
     clrscr();
     menu();
    
      printf("\n enter choice\n");
     ch=getche();
    
     switch(ch)
    {
     case'1':
     add();
     break;
     case'2':
     sort();
     break;
     case'3':
     _display();
     break;
    /* case'4':
     bookdetails();
     break;*/
     case'5':
     exit(0);
     break;
    //default:
    // printf("\n enter a valid choice\n");
    }
    
    }
    }
    void menu(void)
    {
     clrscr();
     printf("\n   book database");
     printf("\n 1.add abook");
     printf("\n 2.sort");
     printf("\n 3.price");
     printf("\n 4.bookdetails");
     printf("\n 5.exit");
    }
    
    void add(void)
     {
      char x[9];
     clrscr();
    
      if(new<40)
      {
       printf("\nenter bookid:");
       gets(x);
       book[new].book_id=atoi(x);
       printf("\nenter book price:");
       gets(x);
       book[new].price=atof(x);
       printf("enter book author name");
      gets(book[new].authername);
      printf("enter book name");
      gets(book[new].bookname);
      new++;
      printf("book entere\n");
     getch();
      }
     else
     printf("not enough  memory");
    
    }
    
    
    
    void sort(void)
    {  int i,o;
        float  temp=0;
    
    
    // struct data temp;
     for(o=0;o<new-1;o++)
    {
     for(i=o+1;i<new;i++)
    {
     if(book[o].price>book[i].price)
    {
     temp=book[o].price;
     book[o].price=book[i].price;
     book[i].price=temp;
    }
    }
    }
    }
    
      void  _display(void)
    {
     int x=0;
     char ch;
    
     printf("\n\n\n displaying books records");
     do
    {
    if(x<new)
     {
     printf("\n record # %d\n",x+1);
     printf("\n book name %s",book[x].bookname);
     printf("\n author name: %s",book[x].authername);
     printf("\n book id %d",book[x].book_id);
     printf("\n book price %f ",book[x].price);
     x++;
     printf("press enter to see the next record or exit by pressing esc key");
     ch=getche();
     if(ch==27)
     break;
    }
    else
     printf("\n \n no more record");
     getch();
     break;
    
    }while(ch!='27');
    
    }

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    I have moved your post into a new thread. Please do not hijack existing threads to ask unrelated questions. If you have an unrelated question then start a new thread.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    I just can't read it!!... It's totally messed up!
    Devoted my life to programming...

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    My intent was to preserve the other thread and not to correct this disastrous post.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Do you use C or C++? ( i think C).
    You say that it does give correct output. Does it compile at all?
    Devoted my life to programming...

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    I wasn't referring to you, Bubba! Relax...
    Devoted my life to programming...

  7. #7
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Where to start on this one? I suspect one of your main problems is that you are interleaving calls to gets and getchar. This usually gives the trouble of newlines in the input giving unexpected results. You need to rethink your methods of getting input from the user. Unfortunately for you, you seem to be just learning C, and so this like asking a small child to do something only adults normally are able to do. That said, I would ditch the usage of gets altogether. If you want to know why, do a board search here on "gets is bad" and you will undoubtedly get a lot of pages to look at on the subject. Instead of gets, you could use fgets. Have a look at this. You should be able to get started with it anyway. Do some reading, make your changes, come back and ask lots of questions. It can be a painful process, but you will be learning how to program, and I would assume that is your goal.
    Last edited by kermit; 07-05-2010 at 12:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-25-2010, 07:14 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 08:13 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21