is_valid - 1Fr3aK2/Cub3d GitHub Wiki

📝 is_valid

This function checks if a specific character exists within a given string.

⚙️ Parameters

Parameter Type Description
arr char* The input string to be searched.
c char The character to search for in the string.

🔁 Returns

Return value Description
bool Returns true if the character is found, false otherwise.

📖 Description

The is_valid function iterates through each character of the input string arr to check if the character c exists in the string.

  • The function loops through the string until it reaches the null terminator (\0).
  • If it finds the character c in the string, it immediately returns true.
  • If the loop completes without finding the character, it returns false.

💡 Example Usage

char *str = "hello";
char ch = 'e';

if (is_valid(str, ch)) {
    printf("Character '%c' found in string!\n", ch);
} else {
    printf("Character '%c' not found in string.\n", ch);
}