slight problem

This is a discussion on slight problem within the C Programming forums, part of the General Programming Boards category; Hey guys, I'm having a slight problem with a module here. Here's the code samples. Code: case '5': fflush(stdin); show_Rec(); ...

  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
    India
    Posts
    515
    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
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    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, 08:55 AM
  2. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  3. Subclassing edit control - slight problem
    By Shag in forum Windows Programming
    Replies: 3
    Last Post: 11-02-2002, 11:33 PM
  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

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