My exercise requires that I can use case-insensitive input. My approch is that I use the tolower and toupper function.
How can I convert the array to lowercase letters?
void KULstrcichr(char *arr, char search)
{
printf("Return value when uppercase character %c is passed to isupper(): %d\n", search, isupper(search));
// The strchr() function returns a pointer to the first occurrence of the character c in the string s.
if (isupper(search))
{
printf("Groß\n");
char lowercasesearch = tolower(search);
printf("Das ist der Output: %s", arr);
char *ptr = strchr(arr, lowercasesearch);
printf("Das ist der Buchstabe: %s", ptr);
}
else
{
printf("Klein\n");
char upercasesearch = toupper(search);
printf("Das ist der Output: %s", arr);
char *ptr = strchr(arr, upercasesearch);
printf("Das ist der Buchstabe: %s", ptr);
}
}
According to the title of the question
your code does not make any sense. You should write your own function similar to
strchr
that is declared in the C Standard likeThe function should be declared and defined the following way
Here is a demonstration program.
The program output is