C Program to Remove All Duplicate Characters in a String

C Program to Remove All Duplicate Characters in a String

C program to remove all duplicate characters in a string; Through this tutorial, we will learn how to remove all duplicate characters in a string using for loop, while loop and function in c programs.

Programs and Algorithm to Remove All Duplicate Characters From String in C

Algorithm and programs to remove all duplicate characters in a string using for loop, while loop and function in c:

  • Algorithm to Remove All Duplicate Characters in a String
  • C Program to Remove All Duplicate Characters in a String using For Loop
  • C Program to Remove All Duplicate Characters in a String using While Loop
  • C Program to Remove All Duplicate Characters in a String using Function

Algorithm to Remove All Duplicate Characters in a String

Use the following algorithm to write a program to remove the duplicate character from a string; as follows:

  1. Start program.
  2. Take input string from user, store it in some variable.
  3. Find and remove all repeated characters of the given string.
  4. Print result
  5. End program

C Program to Remove All Duplicate Characters in a String using For Loop

/* C Program to Remove All Duplicate Character in a String */
 
#include <stdio.h>
#include <string.h>
 
int main()
{
  	char str[100];
  	int i, j, k;
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	 	
  	for(i = 0; i < strlen(str); i++)
  	{
  		for(j = i + 1; str[j] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, j, k;
printf("\n Please Enter any String :  ");
gets(str);
for(i = 0; i < strlen(str); i++)
{
for(j = i + 1; str[j] != '\0'; j++)
{
if(str[j] == str[i])  
{
for(k = j; str[k] != '\0'; k++)
{
str[k] = str[k + 1];
}
}
}
}
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
'; j++) { if(str[j] == str[i]) { for(k = j; str[k] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, j, k;
printf("\n Please Enter any String :  ");
gets(str);
for(i = 0; i < strlen(str); i++)
{
for(j = i + 1; str[j] != '\0'; j++)
{
if(str[j] == str[i])  
{
for(k = j; str[k] != '\0'; k++)
{
str[k] = str[k + 1];
}
}
}
}
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
'; k++) { str[k] = str[k + 1]; } } } } printf("\n The Final String after Removing All Duplicates = %s ", str); return 0; }

The output of the above c program; as follows:

The Final String after Removing All Duplicates = welcom t prgaminus 

C Program to Remove All Duplicate Characters in a String using While Loop

/* C Program to Remove All Duplicate Character in a String */
 
#include <stdio.h>
#include <string.h>
 
int main()
{
  	char str[100];
  	int i, j, k;
  	i = 0;
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	 	
  	while(i < strlen(str))
  	{
  		j = i + 1;
  		
  		while(str[j] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, j, k;
i = 0;
printf("\n Please Enter any String :  ");
gets(str);
while(i < strlen(str))
{
j = i + 1;
while(str[j] != '\0')
{
if(str[j] == str[i])  
{
k = j;
while(str[k] != '\0')
{
str[k] = str[k + 1];
k++;
}
}
j++;
}
i++;
}
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
') { if(str[j] == str[i]) { k = j; while(str[k] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, j, k;
i = 0;
printf("\n Please Enter any String :  ");
gets(str);
while(i < strlen(str))
{
j = i + 1;
while(str[j] != '\0')
{
if(str[j] == str[i])  
{
k = j;
while(str[k] != '\0')
{
str[k] = str[k + 1];
k++;
}
}
j++;
}
i++;
}
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
') { str[k] = str[k + 1]; k++; } } j++; } i++; } printf("\n The Final String after Removing All Duplicates = %s ", str); return 0; }

The output of the above c program; as follows:

Please Enter any String :  c programmer
The Final String after Removing All Duplicates = c progame 

C Program to Remove All Duplicate Characters in a String using Function

/* C Program to Remove All Duplicate Character in a String */
 
#include <stdio.h>
#include <string.h>

void Remove_AllOccurrence(char *str);
 
int main()
{
  	char str[100];
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	 	
  	Remove_AllOccurrence(str);
	
	printf("\n The Final String after Removing All Duplicates = %s ", str);
	
  	return 0;
}

void Remove_AllOccurrence(char *str)
{
	int i, j, k;
	
	for(i = 0; i < strlen(str); i++)
  	{
  		for(j = i + 1; str[j] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
void Remove_AllOccurrence(char *str);
int main()
{
char str[100];
printf("\n Please Enter any String :  ");
gets(str);
Remove_AllOccurrence(str);
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
void Remove_AllOccurrence(char *str)
{
int i, j, k;
for(i = 0; i < strlen(str); i++)
{
for(j = i + 1; str[j] != '\0'; j++)
{
if(str[j] == str[i])  
{
for(k = j; str[k] != '\0'; k++)
{
str[k] = str[k + 1];
}
}
}
}
}
'; j++) { if(str[j] == str[i]) { for(k = j; str[k] != '
/* C Program to Remove All Duplicate Character in a String */
#include <stdio.h>
#include <string.h>
void Remove_AllOccurrence(char *str);
int main()
{
char str[100];
printf("\n Please Enter any String :  ");
gets(str);
Remove_AllOccurrence(str);
printf("\n The Final String after Removing All Duplicates = %s ", str);
return 0;
}
void Remove_AllOccurrence(char *str)
{
int i, j, k;
for(i = 0; i < strlen(str); i++)
{
for(j = i + 1; str[j] != '\0'; j++)
{
if(str[j] == str[i])  
{
for(k = j; str[k] != '\0'; k++)
{
str[k] = str[k + 1];
}
}
}
}
}
'; k++) { str[k] = str[k + 1]; } } } } }

The output of the above c program; as follows:

Please Enter any String :  c programmer
The Final String after Removing All Duplicates = c progame 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *