C Online Compiler
Example: Find First Non-Repeating Character (Brute-Force) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Find First Non-Repeating Character (Brute-Force) #include <stdio.h> #include <string.h> // For strlen int main() { char str[] = "programming"; // Example string int len = strlen(str); char firstNonRepeating = '\0'; // Initialize with null character // Step 1: Iterate through each character of the string for (int i = 0; i < len; i++) { int count = 0; // Reset count for current character // Step 2: For each character, iterate through the string again to count occurrences for (int j = 0; j < len; j++) { if (str[i] == str[j]) { count++; } } // Step 3: If a character appears exactly once, it's a non-repeating character if (count == 1) { firstNonRepeating = str[i]; // Store it as the first found break; // Since we need the *first* one, we can stop } } // Step 4: Print the result if (firstNonRepeating != '\0') { printf("The first non-repeating character is: %c\n", firstNonRepeating); } else { printf("No non-repeating character found.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS