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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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