Â
In this, we are going to see a program to remove repeated character from strings with the help of C Programming Language.
#include <stdio.h>
#include <string.h>
int main()
{
//Input string
char str[30] = "Pencil Programmer";
//find ength of the string
int length = strlen(str);
//Iterate through all the characters
for (int i = 0; i < length; i++)
{
//select a character
char ch = str[i];
//check if the character mathches any other in later part
for (int j = i + 1; j < length; j++)
{
if (str[i] == str[j])
{
//If yes, then shift the right characters to the left
for (int k = j; k < length; k++)
{
str[k] = str[k + 1];
}
length--;
}
}
}
//output string
printf("%s", str);
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP