Yo guys, I am doing a function to display selections of department for the user to input and if the department is chosen, it will then match the department with the department in the database allowing only employees within that department to be displayed, but the employees can be as much as 500 person and I want them to be displayed 10 person at a go before the user hit keypad to display the next 10 meaning to say if I have 500 employees within that department it should
display 10, 10, 10 up to the 500th employee within that department
the problem is after I inserted 21 person to check if it works it
display it display 9 person then hit it display 10 without clearscreen then 2. I wanted it to display 10 then clearscreen before it display the next 10 again.

Here are the codes :

do	{
	printf("\n\n 0) %s\n 1) %s\n 2) %s\n 3) %s\n 4) %s\n \n [Enter the Department to search for employee]: ", Department[0], Department[1], Department[2], Department[3], Department[4]);
   fflush(stdin);
	scanf("%d",&selection);
  	if((selection !=0) && (selection !=1) && (selection !=2) && (selection !=3) && (selection !=4)) {gotoxy(1, 24); printf(" >>invalid Department<< Retry!\a");}
  	} while(selection < 0 || selection > 4);

     clrscr();




            
            printf("\n\n%s%s----------\n", lines, lines);
            printf("ID\tFirst Name\t\tDepartment\t\tPost\n%s%s----------\n", lines, lines);
            for (i=0;i<500;i++)
				{
            if(strcmp(record[i].Department[storage], Department[selection])==0)
            {
            printf("\n\n%s\t%s %s\t\t%s\t\t%s", record[i].ID, record[i].Name, record[i].Name2, record[i].Department[storage], record[i].Post[rank]);
            
            }

               if(i%10==0)
            {
             getchar();

            }
             
             
   			}

really need some help I try to include clrscr(); after the getchar() but it doesn't works thanks in advance

Recommended Answers

All 8 Replies

Try use "system(cls);" instead of "clrscr()". I assume you are using a newer compiler...

commented: Do some searching and find out why this is bad advise. +1

sorry this is a college project so we cant use anymore than just C . I still cant display 10 per 10 properly

sorry this is a college project so we cant use anymore than just C . I still cant display 10 per 10 properly

"system" function is available in C, in stdlib.h. So, I guess you can use it without any restrictions.

Oh i see thanks for the info but may i know how it works? Thanks

Just include <stdlib.h> into your .c file, then, instead "clrscr()", write "system(cls)". This is a call to a system function, that clears the screen.

Just include <stdlib.h> into your .c file, then, instead "clrscr()", write "system(cls)". This is a call to a system function, that clears the screen.

im using borland 5.02 cant use the system(cls) it cant even compile that's funny... Hmmm...

>that's funny...
What's funny is that frrossk made the exact same mistake twice, thus ensuring that the solution wouldn't work. The argument to the system function is a string designating a system shell command, so the correct call would be:

system ( "cls" );

However this is not recommended. While system is a standard function, the argument you pass it can never be completely portable. Most notably is that on DOS and Windows machines, cls will work, but only POSIX machines, clear is the command you need. On top of that, system calls the first program it encounters with a matching name and argument list as specified by the string. So if cls is a malicious program, bad things will happen. If cls is a benign program that does something other than clear the console window, you'll have a strange bug. Finally, system is a slow function. Clearing the screen is usually a common operation in programs that use it, so you want the solution to be as fast as possible. Invoking a system command interpreter is rarely a good idea when there are alternatives.

If you don't care about all of this then I still recommend adding a level of abstraction to make life easier for you down the road:

#include <stdlib.h>

void clear_screen ( void )
{
  system ( "cls" );
}

Then scatter calls to clear_screen across your program. When you find the need to move to a different platform, changes only need to be made to the body of clear_screen rather than however many times you would have called system. Isolating the nonportable aspects of your program from everything else is a good habit to get into even if you only use them once or twice.

>that's funny...
What's funny is that frrossk made the exact same mistake twice, thus ensuring that the solution wouldn't work. The argument to the system function is a string designating a system shell command, so the correct call would be:

system ( "cls" );

However this is not recommended. While system is a standard function, the argument you pass it can never be completely portable. Most notably is that on DOS and Windows machines, cls will work, but only POSIX machines, clear is the command you need. On top of that, system calls the first program it encounters with a matching name and argument list as specified by the string. So if cls is a malicious program, bad things will happen. If cls is a benign program that does something other than clear the console window, you'll have a strange bug. Finally, system is a slow function. Clearing the screen is usually a common operation in programs that use it, so you want the solution to be as fast as possible. Invoking a system command interpreter is rarely a good idea when there are alternatives.

If you don't care about all of this then I still recommend adding a level of abstraction to make life easier for you down the road:

#include <stdlib.h>

void clear_screen ( void )
{
  system ( "cls" );
}

Then scatter calls to clear_screen across your program. When you find the need to move to a different platform, changes only need to be made to the body of clear_screen rather than however many times you would have called system. Isolating the nonportable aspects of your program from everything else is a good habit to get into even if you only use them once or twice.

Thx for correction, Narue...It looks like sometimes my brain takes a break...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.