Parity bit checker

#include <stdio.h>
#include <string.h>

int main() {
    char binary[100], parity;
    int count = 0;

    // Input received binary and parity type
    printf("Enter received binary: ");
    scanf("%s", binary);
    printf("Choose parity - even (e) or odd (o): ");
    scanf(" %c", &parity);

    // Count 1's excluding the parity bit
    for (int i = 0; i < strlen(binary) - 1; i++)
    {
        if (binary[i] == '1')
        {
            count++;
        }
    }

    // Verify the parity bit
    char expected_parity = ((parity == 'e') == (count % 2 == 0)) ? '0' : '1';
    printf("The data is %s.\n", (binary[strlen(binary) - 1] == expected_parity) ? "valid" : "invalid");

    return 0;
}

Comments