By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

10 limiting display

P: n/a
How do you limits employee display where you enter the department for all
the employee within that department be displayed and if lets say they are
100 or so and you have to limits 10 employee per page before entering
anything to display the next 10 again?

Nov 14 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
kimimaro <li************@yahoo.com> scribbled the following:
How do you limits employee display where you enter the department for all
the employee within that department be displayed and if lets say they are
100 or so and you have to limits 10 employee per page before entering
anything to display the next 10 again?


I tried to read that. Twice. Both times I failed to understand what
exactly you want.
Next time, try separating your sentences with punctuation marks like
these:
"," "." "!" "?" ":" ";"
For advanced users, separate paragraphs might help.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush
Nov 14 '05 #2

P: n/a
In article <48******************************@localhost.talkab outprogramming.com>,
kimimaro <li************@yahoo.com> wrote:
How do you limits employee display where you enter the department for all
the employee within that department be displayed and if lets say they are
100 or so and you have to limits 10 employee per page before entering
anything to display the next 10 again?


Try it this way:

Department employee 100 be per or displayed page so and before and if
the how entering you department do anything have for you to to all
limits display limits employee the 10 lets the display next say
employee where 10 they within you again are that enter?

Nov 14 '05 #3

P: n/a

kimimaro wrote:
How do you limits employee display where you enter the department for all the employee within that department be displayed and if lets say they are 100 or so and you have to limits 10 employee per page before entering
anything to display the next 10 again?


As far as the loop control, something using the remainder operator (%)
is typical. As far as stopping then entering, some sort of read from
stdin in used. For portable code, that means reading a line. Any other
way (Hit Any Key To Continue) requires implementation-specific features
that are off-topic here.

Here is a small code fragment that displays numbers from 1 and stopping
after every 5 to wait for a carriage return. This input is not robust,
in reality you need to handle people putting in characters before the
return, and has other safety issues for you to work out. It is only a
demonstration.

int i;

for (i = 1; ; i++)
{
printf("%d\n", i);
if (i%5 == 0)
getchar();
}


Brian

Nov 14 '05 #4

P: n/a
Kenny McCormack <ga*****@yin.interaccess.com> scribbled the following:
In article <48******************************@localhost.talkab outprogramming.com>,
kimimaro <li************@yahoo.com> wrote:
How do you limits employee display where you enter the department for all
the employee within that department be displayed and if lets say they are
100 or so and you have to limits 10 employee per page before entering
anything to display the next 10 again?
Try it this way: Department employee 100 be per or displayed page so and before and if
the how entering you department do anything have for you to to all
limits display limits employee the 10 lets the display next say
employee where 10 they within you again are that enter?


Right, if kimimaro next replies to this with "Thanks! That worked!"
then I'll be really scared...

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"That's no raisin - it's an ALIEN!"
- Tourist in MTV's Oddities
Nov 14 '05 #5

P: n/a
Really sorry for my last post I am too tired then and I only realised that
how broken my engrish(japanese english) are. Ok,
i'll try to type in a proper way now. I want to prompt the user to enter
from the selection 1 to 5 for assigning to a particular department which
I've done that. Now I want to display them by searching on the matched
department where the user want to search such as if they want to view all
employees within Accounting department they enter the correspondant
number. BUT the thing is that I wanted to limits 10 entry to be viewed
before the user hit enter again to display the next 10. If the employee
exceeds 200 it would be a problem to display them all in one go. sorry and
thanks in advance

Nov 14 '05 #6

P: n/a
kimimaro <li************@yahoo.com> scribbled the following:
Really sorry for my last post I am too tired then and I only realised that
how broken my engrish(japanese english) are. Ok,
i'll try to type in a proper way now. I want to prompt the user to enter
from the selection 1 to 5 for assigning to a particular department which
I've done that. Now I want to display them by searching on the matched
department where the user want to search such as if they want to view all
employees within Accounting department they enter the correspondant
number. BUT the thing is that I wanted to limits 10 entry to be viewed
before the user hit enter again to display the next 10. If the employee
exceeds 200 it would be a problem to display them all in one go. sorry and
thanks in advance


You are most probably using some sort of loop (for, while, or something)
to display the matching results. Try adding an int variable which is
initialised to 0 and incremented by 1 every time you enter the loop.
Then when this variable is divisible by 10 you call getchar(). I'd
figure it'd go something like this:

int i=0;
while (/* there are employees left in the department */) {
i++;
/* show the next employee */
if ((i%10) == 0) {
getchar();
}
}

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush
Nov 14 '05 #7

P: n/a

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);
while(strcmp(record[i].Department[storage],
Department[selection])==0) {
i++;
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();
}

}
This is how my display should work but I dont think it is working because
it only prints out the 1st one who matched the same department input by
the user and then the the next one below them even if it doesnt match with
the department

Nov 14 '05 #8

P: n/a
for (i = 1; 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();
}
}
I have 500 employees in my records and i want to compare the department in
the records and the one entered by the user to
match the search while limiting 10 per page before hit again to display
the next 10. This one almost done it but still it displayed fully. There
might be some mistakes here

Nov 14 '05 #9

P: n/a
hi I seems to do ok now since i've been working on it some few hours and
now the problem is after I inserted 21 person to check if it works it
display the 1st person, then 8 person, then 10 person and then 2. It
supposed to display 10, 10 then 1. This is the code:
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();
getch();
clrscr();
}

}

Thanks for helping me out

Nov 14 '05 #10

P: n/a
On Thu, 04 Nov 2004 12:20:28 -0500, "kimimaro"
<li************@yahoo.com> wrote:
hi I seems to do ok now since i've been working on it some few hours and
now the problem is after I inserted 21 person to check if it works it
display the 1st person, then 8 person, then 10 person and then 2. It
supposed to display 10, 10 then 1. This is the code:
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);
fflush is not defined for input streams. If you insist on posting
code that invokes undefined behavior after being told about it, you
will be taken for a troll who does just to see how many people you can
annoy.
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)
This does not cause a pause in the loop every tenth line.

It causes a pause in the loop whenever the record being printed just
happens to be a multiple of 10 from the start of the data base.

For example, if the only records that satisfy your if(strcmp... above
are records 5, 15, 25, 35, etc, then this if will never be true and
you will print everything without pause. On the other hand, if the
records that satisfy the if(strcmp are 5, 10 , 15, 20, 25, etc, you
will pause after every two records are printed.

Your division by 10 needs to be against the number of records printed,
not the number of the record in the database.
{
getchar();
getch();
What was your intent here?
clrscr();
}

}

Thanks for helping me out


<<Remove the del for email>>
Nov 14 '05 #11

P: n/a
> {
getchar();
getch(); What was your intent here? clrscr();
}


hi, my intent was to stop the frame before the user hit enter to clear
screen and then display another 10 employee and stop frame again while
user hit enter again to clear screen to show the next 10 employee. Im
sorry but I dont know how getchar() works and I dont know its function. I
am still having trouble of displaying please help

Nov 14 '05 #12

P: n/a

"kimimaro" <li************@yahoo.com> wrote in message
news:3d******************************@localhost.ta lkaboutprogramming.com...
{
getchar();
getch();

What was your intent here?

clrscr();
}


hi, my intent was to stop the frame before the user hit enter to clear
screen and then display another 10 employee and stop frame again while
user hit enter again to clear screen to show the next 10 employee. Im
sorry but I dont know how getchar() works and I dont know its function. I
am still having trouble of displaying please help

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int match(const char *s,
int c) /* pass zero to match anything */
{
return c = 0 || strchr(s, c) != 0;
}

void pause(void)
{
int c = 0;

printf("Press ENTER to continue");
fflush(stdout);

while((c = getchar()) != '\n' && c != EOF)
;
}

void output(const char *s,
FILE *fp,
size_t line_num,
size_t lines_per_page)
{
char *p = strrchr(s, '\n');

if(p)
*p = 0;

if(lines_per_page && line_num)
if(!(line_num % lines_per_page))
pause();

fprintf(fp, "%3lu: %s\n", (unsigned long)++line_num, s);
}

void select(const char *filename,
int containing,
size_t lines_per_page)
{
char line[100] = {0};
FILE *input = fopen("text.txt", "r");
size_t line_num = 0;

if(!input)
fprintf(stderr, "Cannot open input file '%s'\n", filename);
else
{
printf("%sines from file '%s'",
containing ? "L" : "All l",
filename);

if(containing)
printf(" containing character '%c'", containing);

putchar('\n');
printf("(%lu lines per page):\n", (unsigned long)lines_per_page);

while(fgets(line, sizeof line, input))
if(match(line, containing))
output(line, stdout, line_num++, lines_per_page);

if(!feof(input))
fprintf(stderr, "Error reading file '%s'\n", filename);

printf("\t*** %lu lines found ***\n", (unsigned long)line_num);
fclose(input);
line_num = 0;
}

putchar('\n');
}

int main()
{
select("text.txt", 'e', 10);
select("text.txt", 'r', 5);
select("text.txt", 'z', 20);
select("text.txt", 0, 15);
return 0;
}
-Mike
Nov 14 '05 #13

P: n/a

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:uZ*****************@newsread3.news.pas.earthl ink.net...

I forgot to include the input and
output from a sample run. Here it is:
INPUT (file 'text.txt'):

hi,
my
intent
was
to
stop
the
frame
before
the
user
hit
enter
to
clear
screen
and
then
display
another
10
employee
and
stop
frame
again
while
user
hit
enter
again
to
clear
screen
to
show
the
next
10
employee.
Im
sorry
but
I
dont
know
how
getchar()
works
and
I
dont
know
its
function.
I
am
still
having
trouble
of
displaying
please
help
OUTPUT:

Lines from file 'text.txt' containing character 'e'
(10 lines per page):
1: intent
2: the
3: frame
4: before
5: the
6: user
7: enter
8: clear
9: screen
10: then
Press ENTER to continue
11: another
12: employee
13: frame
14: while
15: user
16: enter
17: clear
18: screen
19: the
20: next
Press ENTER to continue
21: employee.
22: getchar()
23: trouble
24: please
25: help
*** 25 lines found ***

Lines from file 'text.txt' containing character 'r'
(5 lines per page):
1: frame
2: before
3: user
4: enter
5: clear
Press ENTER to continue
6: screen
7: another
8: frame
9: user
10: enter
Press ENTER to continue
11: clear
12: screen
13: sorry
14: getchar()
15: works
Press ENTER to continue
16: trouble
*** 16 lines found ***

Lines from file 'text.txt' containing character 'z'
(20 lines per page):
*** 0 lines found ***

All lines from file 'text.txt'
(15 lines per page):
1: hi,
2: my
3: intent
4: was
5: to
6: stop
7: the
8: frame
9: before
10: the
11: user
12: hit
13: enter
14: to
15: clear
Press ENTER to continue
16: screen
17: and
18: then
19: display
20: another
21: 10
22: employee
23: and
24: stop
25: frame
26: again
27: while
28: user
29: hit
30: enter
Press ENTER to continue
31: again
32: to
33: clear
34: screen
35: to
36: show
37: the
38: next
39: 10
40: employee.
41: Im
42: sorry
43: but
44: I
45: dont
Press ENTER to continue
46: know
47: how
48: getchar()
49: works
50: and
51: I
52: dont
53: know
54: its
55: function.
56: I
57: am
58: still
59: having
60: trouble
Press ENTER to continue
61: of
62: displaying
63: please
64: help
*** 64 lines found ***

-Mike
Nov 14 '05 #14

P: n/a
Hi, i appreciate your work very much but i am doing my college project and
I cannot use anything except pure C programming. I cannot use other
programming language such as c++ sorry to trouble but this is the last bit
of my program that cannot work I will not bother anymore if I can limit 10
employee per page thank you

Nov 14 '05 #15

P: n/a
In article <3d******************************@localhost.talkab outprogramming.com>,
kimimaro <li************@yahoo.com> wrote:
hi I seems to do ok now since i've been working on it some few hours and
now the problem is after I inserted 21 person to check if it works it
display the 1st person, then 8 person, then 10 person and then 2. It
supposed to display 10, 10 then 1. This is the code:


You're pausing when i%10==0, but i isn't counting the number of
employees you've printed; it's counting the number of employees that
you've looked at. You need to create another counter that counts how
many employees have been printed (for example, call it 'j', initialize
it to 0, increment it everytime you print a record, and then pause when
j%10==0).

-- Brett
Nov 14 '05 #16

P: n/a
On Sat, 06 Nov 2004 12:38:23 -0500, in comp.lang.c , "kimimaro"
<li************@yahoo.com> wrote:
Hi, i appreciate your work very much but i am doing my college project and
I cannot use anything except pure C programming. I cannot use other
programming language such as c++ sorry to trouble but this is the last bit
of my program that cannot work I will not bother anymore if I can limit 10
employee per page thank you


I expect you're using a loop to display your employees on the screen. Then
use a counter and whenever it has a value which is a multiple of ten, use
getchar() to wait for the user to press enter.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #17

P: n/a

"kimimaro" <li************@yahoo.com> wrote in message
news:11******************************@localhost.ta lkaboutprogramming.com...
Hi, i appreciate your work very much but i am doing my college project and
I cannot use anything except pure C programming.
The code I posted is pure (standard) C.
I cannot use other
programming language such as c++
There is no C++ code in my post.

sorry to trouble but this is the last bit
of my program that cannot work I will not bother anymore if I can limit 10
employee per page thank you


My example should show you everything you need.

-Mike
Nov 14 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.