Enum pointer

PHOTO EMBED

Sun Jun 09 2024 11:45:30 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c #pointer

#include <stdio.h>

enum Contains_Result
{
 ABSENT,
 PRESENT
};

enum Contains_Result contains(char* cstring, char find);

int main(void)
{
    char buffer1[] = "Hello Programming 1 Students";
    char buffer2[] = "Learn to program using arrays and pointers!";
    int found_d = contains(buffer1, 'd');
 
    if (found_d == PRESENT)
    {
        printf("buffer1 contains d\n");
    }
    else
    {
        printf("buffer1 does not contain d\n");
    }
 
    found_d = contains(buffer2, 'd');
 
    if (found_d == PRESENT)
    {
        printf("buffer2 contains d\n");
    }
    else
    {
        printf("buffer2 does not contain d\n");
    }
 
 	// The following function tests your code.
	// Do not modify the following code.
	test();
	
    return 0;
}

enum Contains_Result contains(char* cstring, char find)
{
 // TODO: Insert your code here...
 while (*cstring != '\0')
    {
        if (*cstring == find)
        {
            return PRESENT;
        }
        cstring++;
    }
    return ABSENT;
}
content_copyCOPY

Input Expected User input buffer1 contains d buffer2 contains d Test input does not contain d The objective of this exercise is to implement the contains function which searches for a specific character within a given C-string. The function should return an enumerated value, PRESENT or ABSENT, indicating whether the character exists in the C-string or not. The main function should then test this functionality. Requirements Enumerated Type Define an enum Contains_Result with the following possible values: ABSENT PRESENT Function Definition Define the function enum Contains_Result contains(char* cstring, char find) that takes the following arguments: A char* cstring representing the C-String to search within. A char find representing the character to find. The function should return PRESENT if the character is found, and ABSENT otherwise. Main Function Call contains with two predefined C-Strings, buffer1 and buffer2, and print out whether the character 'd' is present in each string. Add another two array declarations and initializations in the main function. Make sure one of the new calls to contains checks for a value that exists, and the other checks for a value that does not exist.