943,361 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2568
  • C RSS
Nov 5th, 2004
0

limitations of 10 employees per page

Expand Post »
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
Last edited by alc6379; Nov 7th, 2004 at 5:37 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimimaro is offline Offline
11 posts
since Oct 2004
Nov 5th, 2004
1

Re: limitations of 10 employees per page

Try use "system(cls);" instead of "clrscr()". I assume you are using a newer compiler...
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004
Nov 5th, 2004
0

Re: limitations of 10 employees per page

sorry this is a college project so we cant use anymore than just C . I still cant display 10 per 10 properly
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimimaro is offline Offline
11 posts
since Oct 2004
Nov 5th, 2004
0

Re: limitations of 10 employees per page

Quote originally posted by kimimaro ...
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.
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004
Nov 5th, 2004
0

Re: limitations of 10 employees per page

Oh i see thanks for the info but may i know how it works? Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimimaro is offline Offline
11 posts
since Oct 2004
Nov 5th, 2004
0

Re: limitations of 10 employees per page

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.
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004
Nov 6th, 2004
0

Re: limitations of 10 employees per page

Quote originally posted by frrossk ...
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kimimaro is offline Offline
11 posts
since Oct 2004
Nov 6th, 2004
0

Re: limitations of 10 employees per page

>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:
  1. 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:
  1. #include <stdlib.h>
  2.  
  3. void clear_screen ( void )
  4. {
  5. system ( "cls" );
  6. }
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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 8th, 2004
0

Re: limitations of 10 employees per page

Quote originally posted by Narue ...
>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:
  1. 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:
  1. #include <stdlib.h>
  2.  
  3. void clear_screen ( void )
  4. {
  5. system ( "cls" );
  6. }
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...
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004

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: making sorted lists (was: Help Me!)
Next Thread in C Forum Timeline: finding the highest value help





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


Follow us on Twitter


© 2011 DaniWeb® LLC