Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:18:33+00:00 2026-06-13T16:18:33+00:00

So this program is supposed to unjumble a word to show valid words of

  • 0

So this program is supposed to unjumble a word to show valid words of the same length. This was an assignment that required dynamic memory allocation within functions and got rather messy. In the beginning of the program I have to dynamically allocate memory for a dictionary of length n. The dictionary we were given was length 10000 and the max length for words was 20 characters. I chose to dynamically create an array of permutations of each word then compare them to words in the dictionary with a binary search using strcmp (All words entered in by the user and in the dictionary were all caps making this a viable method). The entire program worked through the first iteration minus duplicate permutations that were valid words and the while loop exiting prematurely. I use the function Welcome() at the end of the while loop to ask whether or not the user would like to unscramble another word and it prints everything in that function but does not allow me to scan in a value for choice.

Some other specs:

  • user enters “y” or “Y” to denote they would like to play

I have not tried anything to solve this because I can not think of any reason that a while loop would just exit. Especially because choice should still be “y” or “Y” even if I am not allowed to scan in a new value.

This is main.

    int main() {


        char** dictionary;
        int num_words;

        // defined FILE* outside of file read in function to avoid returning local variable address
        FILE* ifp = fopen("Dictionary.txt", "r");

        fscanf(ifp, "%d", &num_words);

        dictionary = FileReadIn(num_words, ifp);

        char choice = Welcome();

        // main part of program Im unsure why it exits after its first iteration
        while ((choice == 'y') || (choice == 'Y')) {

            char* letters = LettersReadIn();

            // Calculates number of permutations which is (numletters)!
            long num_permutations = Factorial(strlen(letters));

            // Sets up permutations through malloc
            char** permutations = (char**)malloc((num_permutations) * sizeof(char*));

            int i;
            for (i = 0; i < num_permutations; i++) {
                permutations[i] = (char*)malloc(MAXWORDLENGTH * sizeof(char));
            }

            // Creates all permutations of the letters entered in by the user in a recursive function
           RecursivePermute(letters, 0, permutations);

           // Created the WordIndices array in order to keep track of which indices in the permutations array are valid words
           // Could not get the program to work when I created wordindices in Viable Words
           // Viable Words checks each permutation against words in the dictionary using a binary search 
           // which compared each word lexicographically with strcmp
           int* word_indices = (int*)malloc(num_permutations * sizeof(int));
           ViableWords(permutations, dictionary, num_permutations, num_words, word_indices);

           // Prints each index in permutations that is a valid word
           // valid word indices stored in word indices
           PrintWords(permutations, num_permutations, letters, word_indices);

           // frees permutations and word indices
           free(permutations);
           free(word_indices);

           choice = Welcome();
     } // End While loop

return 0;
} // End main

And this is the welcome function.

    char Welcome() {

         printf("Welcome to the Jumble Puzzle Solver!\n");
         printf("Would you like to enter a jumbled word?\n");

         char choice;
         scanf("%c", &choice);

   return choice;
   }// End Welcome

So essentially my questions are why causes this to occur and what is a solution.

If you need any other information please let me know, also if you see anything else that you would improve please let me know as well. I am fairly new to programming so I would love some constructive criticism.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:18:34+00:00Added an answer on June 13, 2026 at 4:18 pm

    The reason is scanf leaves a newline character in the input buffer after reading the input which is not cleared before reading the next character.

    Use getchar() to consume the newline character:

    scanf("%c", &choice);
    getchar(); 
    

    Or tell scanf() to ignore the whitespaces in the input buffer by using a leading space in the format string:

    scanf(" %c", &choice);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent many hours working on this program that is supposed to play
This program is supposed to store each word given in standard input stream and
This program is supposed to create a button that the user can press to
This program is supposed to determine how many units are stored in the value
I wrote this short program which has a tiny GUI. Its supposed to allow
I am supposed to modified this Sierpinski's triangle program to count the number of
This program stores pairs in a map, counting the number of times a word
This program supposed to find command line arguments entered on Unix which ends with
Hi, I'm very new to programming, for this program i am supposed to be
This program has 2 classes with a main method and is supposed to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.