C program to print all non repeating character in string

To find the non repeating characters in a given string, we will first iterate the each characters of string and records the count. To records the counts we will have one more integer array which will store the frequency of each characters. At last will print only those character that occurs only one time.

How our program will behave?

  • Our program will take one string as an input.
  • We will have one extra integer array to keep the frequency of all characters of string.
  • Now we will print only those characters that occurs only once in string.

C Program to print all non repeating characters in string

#include <stdio.h>
int main()
{
    //Initializing variables.
    char str[100];
    int i;
    int freq[256] = {0};
    printf("C Program to find all non repeating character\n");
    printf("Enter the string: ");
    scanf("%[^\n]",str);
    //Here we are calculating the frequency of all characters
    for(i = 0; str[i] != '\0'; i++)
    {
        freq[str[i]]++;
    }
    printf("Character which has no repetitions are \n");
    for(i = 0; i < 256; i++)
    {
        //Here is the check to print only character
        //which has came only once
        if(freq[i] == 1)
        {
            printf("%c ", i);
        }
    }
    return 0;
}

Output

C program to find all non repeating character in string

Share on

Also Prepare Below Important Question

Interview Questions Categories

C Programming Interview Preparation

Core Java Programming Interview Preparation

Python Programming Interview Preparation