Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer it with C (Only C). Here is Testing code, Please try with this testing code. #include #include a1_question2.h void checkAndPrint(int expected[], int result[])

image text in transcribed

Please answer it with C (Only C).

Here is Testing code, Please try with this testing code.

#include

#include "a1_question2.h"

void checkAndPrint(int expected[], int result[]) {

if (expected[0] == result[0] && expected[1] == result[1]) {

printf("[%d, %d] is the same as [%d, %d], PASS ",

expected[0], expected[1], result[0], result[1]);

} else {

printf("[%d, %d] is not the same as [%d, %d], FAIL ",

expected[0], expected[1], result[0], result[1]); }

}

int main() {

char* arrA[] = {"ch", "a", "A", "cat", "jump", "rep", "c"};

char* arrB[] = {"x3", "at", "ch", "ed", "!", "hat"};

int result[] = {-1, -1};

//both 0, 1 and 6, 5 are correct

findElements(arrA, 7, arrB, 6, "chat", result);

checkAndPrint((int[]){0, 1}, result);

checkAndPrint((int[]){6, 5}, result);

findElements(arrA, 7, arrB, 6, "A!", result); //should put the values 2, 4 in result

checkAndPrint((int[]){2, 4}, result);

findElements(arrA, 7, arrB, 6, "!A", result); //should put the values -1, -1 in result

checkAndPrint((int[]){-1, -1}, result);

findElements(arrA, 7, arrB, 6, "CMPTx3", result); //should put the values -1, 0 in result for partial match

checkAndPrint((int[]){-1, 0}, result);

findElements(arrA, 7, arrB, 6, "hat", result); // should put the values -1, 5 in result for partial match

checkAndPrint((int[]){-1, 5}, result);

findElements(arrA, 7, arrB, 6, "chach", result); //should put the values -1, -1 in result

// because two partial matches with should not be confused with an exact match

checkAndPrint((int[]){-1, -1}, result);

findElements(arrA, 7, arrB, 6, "", result); //should put the values -1, -1 in result

checkAndPrint((int[]){-1, -1}, result);

return 0;

}

Write a function that takes in 6 parameters: a char* array, its size, another char* array, its size, a char array as the target, and an int array of size 2 ; and performs the following: Find the index of a cstring from the first char* array and the index of another cstring from the second char* array, where those two cstrings will form the target cstring, and put those indexes into the int array. If there are multiple answers, any answer will do. If no answer exists, put the values 1,1 in the int array. Use this function header: void findElements(char* arrA[], unsigned int sizeA, char* arrB[], unsigned int sizeB, char* target, int* result) For example: Given the arrA: { "ch", "a", "A", "cat", "jump", "rep", "c" } and the arrB: {"x3 ", "at", "ch", "ed", "!", "hat" } findElements(arrA, 7 , arrB, 6, "chat", result) should put the values 0,1 in result (6,5 will also work, but not 0, 5) findElements(arrA, 7, arrB, 6, "A!", result) should put the values 2,4 in result findElements(arrA, 7 , arrB, 6, "!A", result) should put the values 1,1 in result findElements(arrA, 7, arrB, 6, "CMPTx3", result) should put the values 1,0 in result for partial match findElements(arrA, 7, arrB, 6, "hat", result) should put the values 1,5 in result for partial match findElements(arrA, 7, arrB, 6, "chach", result) should put the values 1,1 in result because two partial matches with extra characters in-between should not be confused with an exact match findElements(arrA, 7, arrB, 6, "'", result) should put the values 1,1 in result You can assume all elements (cstrings) in the first and second arrays have at least one character and up to 63 characters, and there is no repetition within the same array. Letters are case-sensitive. Only include the function definition (and your helper functions, if any) in the source file and name it as a1_question2.c. Do not use recursion in your

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions