Hi I am doing a program where I am simulating a crossword puzzle. I have a while loop that reads the user input, and inisde I have another while loop. What i need to do is exit the inner loop and start back at the beginning.
here is my code:
#include
#include
#include
#include
#define DIMENSION 12
#define WORD_SIZE 10
#define CLUE_MAX 25
#define MAX_CLUES 10
void updatePuzzle(char crossword[DIMENSION][DIMENSION],char word[WORD_SIZE+1],char row,int col, char dir);
void initPuzzle(char crossword[DIMENSION][DIMENSION]);
void solvingPuzzle(char crossword[][DIMENSION], char tempCrossword[][DIMENSION]);
char crossword[DIMENSION][DIMENSION];
void printCrossword(char crossword[][12]) ;
void printClues(char clues[][CLUE_MAX+1],char rows[], int cols[], char directions[],int numWords);
int main(int argc, char *argv[]) {
char crossword[DIMENSION][DIMENSION];
char tempCrossword[DIMENSION][DIMENSION];
char puzzle_word[WORD_SIZE+1], row_letter, direction, clue[CLUE_MAX+1], c;
int i, j,column_number;
int numWords;
//variables to store clue information
char clues[MAX_CLUES][CLUE_MAX+1];
char rows[MAX_CLUES];
int cols[MAX_CLUES];
char directions[MAX_CLUES];
numWords = 0;
initPuzzle(crossword);
printCrossword(crossword);
while((c!= ‘.’) && numWords < MAX_CLUES) {
printf("\n");
printf("Enter new clue (type . if finished):");
c = getchar();
if(c == '.') {
printf("\n");
break;}
i=0;
while ((c != ' ')) {
puzzle_word[i] = c;
i++;
if((((c>=’A’) && (c<='Z')) ||
((c>=’a’) && (c<='z'))) == 0){
printf("Puzzle word format is incorrect, Enter new clue (type . if finished):\n");
//******* HERE is the problem I need to be able to exit here and then begin the outer while loop from the beginning. At the bottom is what it should look like.
}
c = getchar();
//if(puzzle_word[i] = {0}) {
// printf("Less than 5 fields provided, Enter new clue (type . if finished):");
//}
}
puzzle_word[i] = '\0';
c = getchar();
row_letter = c;
if((c>‘l’) || (c<'a')) {
printf("Starting position format is incorrect, Enter new clue (type . if finished):");
}
c = getchar();
scanf("%d", &column_number);
if((column_number<0) || (column_number>11)) {
printf(“Starting position format is incorrect, Enter new clue (type . if finished):”);
}
//Skip spaces
c = getchar();
while(c == ‘ ‘ || c == ‘\t’)
c = getchar();
direction = c;
if((c != ‘a’) && (c != ‘d’)) {
printf(“Direction format is incorrect, Enter new clue (type . if finished):”);
}
c = getchar();
//skip spaces
c = getchar();
while(c == ‘ ‘ || c == ‘\t’)
c = getchar();
i=0;
while ((c != ‘\n’)) {
clue[i] = c;
i++;
if(((c>=’a’) && (c<='z')) == 0) {
printf("Clue format is incorrect, Enter new clue (type . if finished):");
}
c = getchar();
}
clue[i] = '\0';
//second while loop
//store new information
rows[numWords] = row_letter;
cols[numWords] = column_number;
directions[numWords] = direction;
strcpy(clues[numWords],clue);
updatePuzzle(crossword,puzzle_word,row_letter,column_number,direction);
printCrossword(crossword);
printClues(clues,rows,cols,directions,numWords);
numWords++;
}
//Do the end of stage one stuff
//}
printf("End of stage 1, proceeding to puzzle solving stage\n");
printf("\n");
solvingPuzzle(crossword, tempCrossword);
printCrossword(tempCrossword);
printf("\n");
//stage 2 stuff
j= 0;
while((c!= '.') && (numWords < MAX_CLUES)) {
printf("Enter guess (type . if finished):");
c = getchar();
if(c == '.') {
printf("\n");
break;}
while ((c != ' ')) {
puzzle_word[j] = c;
if(puzzle_word[j] == puzzle_word[i]){
}
j++;
c = getchar();
}
puzzle_word[j] = '\0';
}
return 0;
}
void initPuzzle(char crossword[][DIMENSION]){
int row,column;
for(row=0; row