int main(void) { char text[] = "According to a researcher at Cambridge University, it doesn't matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole."; srand(time(NULL)); size_t i,len=0; for (i=0; i<sizeof(text); i++) { if (isalpha(text[i])) { len++; } else { shuffleWord(text + i - len, len); len = 0; } } printf("%s\n",text); return 0; }
/*********************************************************** synopsis: do all of the initialisation for a new game: build the screen get a random word and generate anagrams (must get less than 66 anagrams to display on screen) initialise all the game control flags inputs: head - first node in the answers list (in/out) dblHead - first node in the dictionary list screen - the SDL_Surface to display the image letters - first node in the letter sprites (in/out) outputs: n/a ***********************************************************/ static void newGame(struct node** head, struct dlb_node* dlbHead, SDL_Surface* screen, struct sprite** letters) { char guess[9]; char remain[9]; int happy = 0; /* we don't want any more than ones with 66 answers */ /* - that's all we can show... */ int i; /* show background */ strcpy(txt, language); ShowBMP(strcat(txt,"images/background.bmp"),screen, 0,0); destroyLetters(letters); assert(*letters == NULL); while (!happy) { char buffer[9]; getRandomWord(buffer, sizeof(buffer)); strcpy(guess,""); strcpy(rootWord, buffer); bigWordLen = strlen(rootWord)-1; strcpy(remain, rootWord); rootWord[bigWordLen] = '\0'; /* destroy answers list */ destroyAnswers(head); /* generate anagrams from random word */ ag(head, dlbHead, guess, remain); answersSought = Length(*head); happy = ((answersSought <= 77) && (answersSought >= 6)); #ifdef DEBUG if (!happy) { Debug("Too Many Answers! word: %s, answers: %i", rootWord, answersSought); } #endif } #ifdef DEBUG Debug("Selected word: %s, answers: %i", rootWord, answersSought); #endif /* now we have a good set of words - sort them alphabetically */ sort(head); for (i = bigWordLen; i < 7; i++){ remain[i] = SPACE_CHAR; } remain[7] = '\0'; remain[bigWordLen]='\0'; shuffleWord(remain); strcpy(shuffle, remain); strcpy(answer, SPACE_FILLED_STRING); /* build up the letter sprites */ assert(*letters == NULL && screen != NULL); buildLetters(letters, screen); addClock(letters, screen); addScore(letters, screen); /* display all answer boxes */ displayAnswerBoxes(*head, screen); gotBigWord = 0; score = 0; updateTheScore = 1; gamePaused = 0; winGame = 0; answersGot = 0; gameStart = time(0); gameTime = 0; stopTheClock = 0; }