C Program to Get a Non-Repeating Character From the Given String
This tutorial explains c program to get a non-repeating character from the given string with C source code, sample output, and step-by-step execution flow.
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "swiss";
int count[256] = {0}, i;
for (i = 0; str[i]; i++) count[(unsigned char)str[i]]++;
for (i = 0; str[i]; i++) {
if (count[(unsigned char)str[i]] == 1) { printf("First non-repeating character: %c
", str[i]); break; }
}
return 0;
}
First non-repeating character: w
In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.
