Ask Question
22 January, 14:11

in c Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list will always contain less than 20 words. Each word will always contain less than 10 characters and no spaces.

+1
Answers (1)
  1. 22 January, 15:39
    0
    see explaination

    Explanation:

    //Include required header file.

    #include

    //Define the function isWordContainChar () having the

    //required parameters.

    int isWordContainChar (char * req_word, char search_char)

    {

    //Declare required variable.

    int i;

    //Start a for loop to traverse the string given in

    //the function parameter.

    for (i = 0; req_word[i]! = '/0'; i++)

    {

    //If the current character in the gievn word is

    //matched with the character which needs to be

    //found in the word, then return 1.

    if (req_word[i] = = search_char)

    {

    return 1;

    }

    }

    //Otherwise, return 0.

    return 0;

    }

    //Start the execution of the main () method.

    int main (void)

    {

    //Declare the required variables.

    int num_words, index, word_index;

    char str_word[20][10];

    char searchCharacter;

    //Prompt the user to enter the number of words.

    scanf ("%d", &num_words);

    //Prompt the user to enter the required words using a

    //for loop and store them into an array.

    for (index = 0; index < num_words; index++)

    {

    scanf ("%s", str_word[index]);

    }

    //Prompt the user to enter a required character which

    //needs to be found in a word.

    scanf (" %c", &searchCharacter);

    //Traverse the words stored in the array using a for

    //loop.

    for (index = 0; index < num_words; index++)

    {

    //Call the function isWordContainChar () with

    //required arguments in rach iteration and if the

    //value returned by this function is not 0, then

    //display the current string in the array.

    if (isWordContainChar (str_word[index],

    searchCharacter) ! = 0)

    {

    printf ("%s/n", str_word[index]);

    }

    }

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “in c Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers