示例#1
0
int main() {

	struct linked_list *list; 
	struct list_data* entry;
	int i;

	list = getNewList();

	// Making list entries.
	for (i=1; i < 100; i++) {
		entry = (struct list_data*)allocMem(sizeof(struct list_data));
		sprintf(entry->blah,"This is entry %d!\n",i);
		printf( "Before pushListEntry\n");
		pushListEntry(entry,list);
	}

	// Get one item

	entry = (struct list_data *) getListEntry(10,list);
	printf("FETCHED 10 --> %s \n",entry->blah);

	//Iterate
	iterateListCallback(callback,list);

	// Now dumping them.. (disabled for free test)
	/*
	while((entry = (struct list_data*) popListEntry( list ) )) {
		if(entry == NULL || list->stop == NULL) {
			break;
		}
		printf("DATA --> %s \n",entry->blah);
	}
	*/

	freeList(list,1);
	printMemStats();

	// Add some new lists..
	//list = getNewList();
	//list = getNewList();

	printf( "Done !\n" );
	return 0;
}
示例#2
0
int main() {

	struct linked_list *list; 
	struct list_data* entry;
	int i;

	list = getNewList();

	initializeSorter(NULL, list, 1);

	for (i=0; i < 15; i++) {
		entry = (struct list_data*)allocMem(sizeof(struct list_data));
		pushListEntry(entry,list);
	}

	// Get one item a few times..
	entry = (struct list_data *) getListEntry(10,list);
	entry = (struct list_data *) getListEntry(10,list);
	entry = (struct list_data *) getListEntry(10,list);
	entry = (struct list_data *) getListEntry(12,list);
	entry = (struct list_data *) getListEntry(12,list);

	printf("List order before sort..\n");
	iterateListCallback(callback,list);

	printf("Waiting for sort to kick in.. \n");
	sleep(6);
	printf("List order after sort\n");
	iterateListCallback(callback,list);

	freeList(list,1);
	printMemStats();

	printf( "Done !\n" );
	return 0;
}
示例#3
0
/* Calls relevant functions to play the game and allows user to guess letter after letter
 * and checks if the user has won or lost after each guess.*/
void userLoop(){
    createLists(); // This reads the dictionary and generates an array of all lists of all word lengths
    char guess;    // This is the variable where the current letter being guessed is kept
    int next=0;    // Prevents duplication of code on first pass.
    int won=0;     // Keeps track of whether the game has been won or lost
    int hard= difficulty();  //User chosen difficulty level
    int numberOfLetter=numberOfLetters();
    //number of wrong guesses left before game is over
    int guessNumber=numberOfGuesses();
    
    
    printf("To play, type in a single letter as a guess.\n");
    printf("You have %i guesses remaining.\n", guessNumber);
    // game plays while the user still has some  guesses left and has not won
    
    guess = obtainGuess();      //Gets first guess from user
    insertInList(&head, guess );//Puts guessed letter in list of guessed letters
                                //All word families of user defined length are created
    generateDescriptions(&lists[numberOfLetter],numberOfLetter,guess);
    currentStatus();            // The status of game is shown to the user
    getNewList(hard);               /*Finds the biggest members list from current
                                *families and makes it the new main list of possible words*/
    
    
   //This is the loop that allows the game to proceed. The first part of the loop is similar to above.
    while ((guessNumber)>0 && won==0) {
        if (next==1) {// prevents and initial duplication
            printf("You have %i guesses remaining.", guessNumber);
            // prints the status of the uncovered letters
            guess = obtainGuess();       //Gets first guess from user
            insertInList(&head, guess ); //Adds the guessed letter to the list containing all guessed letters
            currentFamily=NULL;          //Resets list of current families
            
            //All word families of user defined length are created
            generateDescriptions(&currentWordList,numberOfLetter,guess);
            //All word families of user defined length are created
            /*Finds the biggest members list from current
             *families and makes it the new main list*/
            getNewList(hard);
            currentStatus();
        }
        // Allows the first part of the loop to be run on all subsequent guesses.
        next=1;
        
        // Lets the use know if they uncovered a letter.
        if (checkIfFound(guess,numberOfLetter)) {
            printf("\n \n \n Wrong!\n");
        }
        else {
            printf("\n \n \n Correct.\n");
            
        }
        //  The number of  guesses remaining decreases after each guess
        guessNumber--;
        // Checks to see if the user has uncovered all letters
        if (checkWin(numberOfLetter)) {
            printf("You Win!!");
            won=1;
        }
        
    }
    printf("Game over. You uncovered:");
    //Shows final game state
    currentStatus();
    //Shows user a word that fits the currently visible letter pattern.
    printf("The word was: %s\n",currentFamily->members->word);
    
}