Thread: slight problem

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    37

    slight problem

    Hey guys,
    I'm having a slight problem with a module here.
    Here's the code samples.

    Code:
                case '5':
                                      fflush(stdin);
                                      show_Rec();                                        
                                      clrscr();
                                      menu();
                                      break;
    Code:
    
    void show_Rec(void)
    {
          char buf[BUFSIZ] ;
          int i;
    
          if ((rslpf = fopen("C:\\rslpf.txt", "r")) == NULL)
          {
                printf("\a! Error: Cannot open file");
                exit(EXIT_FAILURE);
          }
    
          i=0;
          clrscr();
    
          while (fgets(buf, sizeof(buf), rslpf) != NULL)
          {
                printf("%s", buf);
    
                ++i;
    
                if  ( i > 6 )                  /* (0-6) five entries in  record followed by two newline characters*/
                {                              /* press enter to skip line and display next record */
                      getchar();               /* make i zero to start over */
                      i=0;
                }
          }fclose(rslpf);
    }
    The problem here is that after the show_Rec function has been executed and the menu has been called, the last record from the file is still displaying on the screen at the bottom. I have tried clrscr(); but it doesnt work.
    I would greatly appreciate any ideas you may have.

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    what compiler r u on??
    dont use fflush(stdin) fflush is not defined for input streams
    also, clrscr() is non portable, dont use it..
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    37
    I am using borland c++ builder X.
    I know that while(getchar()!='n') can be substituted for fflush(stdin).
    However, I have no idea of a substitute for clrscr().
    I'll need some advice here too.
    Thanks for the tip though.

  4. #4
    Quote Originally Posted by duvernais28
    However, I have no idea of a substitute for clrscr().
    FAQ: Clear the screen?


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    37
    Hey thanks alot Stack Overflow. Option 2 worked very well. I wasn't sure what screensize to use so I just defined it as 500. That should hold for now...
    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 09:55 AM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. Subclassing edit control - slight problem
    By Shag in forum Windows Programming
    Replies: 3
    Last Post: 11-03-2002, 12:33 AM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM