kimimaro said:
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