Beispiel #1
0
/*
 * Show current scores.  This must be called after savescore, if
 * savescore is called at all, for two reasons:
 * - Showscores munches the time field.
 * - Even if that were not the case, a new score must be recorded
 *   before it can be shown anyway.
 */
void
showscores(int level)
{
	struct highscore *sp;
	int i, n, c;
	const char *me;
	int levelfound[NLEVELS];

	if (!gotscores)
		getscores((FILE **)NULL);
	(void)printf("\n\t\t    Tetris High Scores\n");

	/*
	 * If level == 0, the person has not played a game but just asked for
	 * the high scores; we do not need to check for printing in highlight
	 * mode.  If SOstr is null, we can't do highlighting anyway.
	 */
	me = level && SOstr ? thisuser() : NULL;

	/*
	 * Set times to 0 except for high score on each level.
	 */
	for (i = MINLEVEL; i < NLEVELS; i++)
		levelfound[i] = 0;
	for (i = 0, sp = scores; i < nscores; i++, sp++) {
		if (levelfound[sp->hs_level])
			sp->hs_time = 0;
		else {
			sp->hs_time = 1;
			levelfound[sp->hs_level] = 1;
		}
	}

	/*
	 * Page each screenful of scores.
	 */
	for (i = 0, sp = scores; i < nscores; sp += n) {
		n = 20;
		if (i + n > nscores)
			n = nscores - i;
		printem(level, i + 1, sp, n, me);
		if ((i += n) < nscores) {
			(void)printf("\nHit RETURN to continue.");
			(void)fflush(stdout);
			while ((c = getchar()) != '\n')
				if (c == EOF)
					break;
			(void)printf("\n");
		}
	}

	if (nscores == 0)
		printf("\t\t\t      - none to date.\n");
}
Beispiel #2
0
int main(void)
{

	struct Ordered_array * ptr;
	int(*fp)(void *, void *);
	assert(sizeof(int) <= sizeof(void *));	/* check on assumption */
	
	fp = comp_int;
	
	ptr = create_Ordered_array(fp);
	printem(ptr, printit);	
	
	
	while (1) {
		int index;
		int v;
		
		printem(ptr, printit);
		printf("\nEnter a search value, or -1:");
		scanf("%d", &v);
	
		if(v == -1)
			break;

		index = find_in_Ordered_array(ptr, (void *) v);
		if(index < 0) {
			printf("Not found! - adding it!\n");
			insert_in_Ordered_array(ptr, (void *) v);
			}
		else {
			printf("Found! - removing it\n");
			remove_from_Ordered_array(ptr, index);
			}
		}
		
	destroy_Ordered_array(ptr);
	printf("Done!\n");
	return 0;
}