I got an assignment from my teacher to write a code that compares a given word to a bunch of words located in an array of strings. If the word in the array is lexicography smaller than the word given, I need to put it inside a new array. else, I'm moving to the next word. for example; given word: hello arr=bus, alpha, world, java. new array=bus,alpha. I wrote a code that does that using STRCMP, but the computer throws me out when it gets to the strcpy part. this is my code
char** LowerSTR(char* arr[], int size_arr, char* str, int* size_res)
size_res = 0;
char** newArr= (char**)calloc(size_arr, sizeof(char));
for (int i = 0; i < size_arr; i++)
{
if (strcmp(str, arr[i])==1)
{
for (int k = 0; k <size_arr;k++)
{
strcpy(newArr[k], arr[i]);
}
size_res++;
}
}
if (size_res == 0)
return NULL;
else return newArr;}
maybe I should use STRCAT instead?
please help :\