To Write a C program to remove the repeated characters in
the entered expression or in entered characters(i.e)
removing duplicates.

Answers were Sorted based on User's Feedback



To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / adarsh

#include<stdio.h>
#include<string.h>

main()
{
char a[100],b[100]={0};
printf("Enter the string\n");
scanf("%s",a);
int f=strlen(a);
int i,j,k=0,count=0;
for(i=0;i<f;i++)
{
for(j=0;j<i;j++)
{
if(a[i]==b[j])
{
count=1;
}
}
if(count==0)
{
b[k++]=a[i];

}
count=0;
}

for(j=0;j<strlen(b);j++)
{
printf("%c",b[j]);
}
}

Is This Answer Correct ?    154 Yes 89 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / ashish

#include<stdio.h>
#include<string.h>
void main()
{
int tail=1;
char str[200];
int d=0,i;
clrscr();
printf("\nenter the string:");
scanf("%s",&str);
d=strlen(str);
for(i=1;i<d;++i)
{
int j;
for(j=0;j<tail;++j)
{
if(str[i]==str[j])
break;
}

if(j==tail)
{
str[tail]=str[i];
++tail;
}
}
str[tail]=0;

printf("the string is:%s",str);
getch();
}

Is This Answer Correct ?    30 Yes 16 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / tls

int remove_duplicates(char *str)
{
int char_check=0;
int i,j;
char ch;

if(str == NULL)
return 0;

/* check from 1st character in the string */
while(str[char_check]) {

ch = str[char_check];

i = j = char_check + 1;

/* logic to remove the repeated character */
while(str[i]) {
if(str[i] != ch) {
str[j] = str[i];
j++;
}
i++;
}
str[j]='\0';

char_check++;
}
printf("String after removing duplicates : %s\n",str);
return 1;
}

Is This Answer Correct ?    63 Yes 52 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / srikanth

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *input_str,*output_str;
int str_len,i,j,duplicate_count;
clrscr();
printf("\n Enter your String : ");
scanf("%s",input_str);
str_len=strlen(input_str);
output_str[0]=input_str[0];
output_str[1]='\0';
for(i=1;i<str_len;i++)
{
duplicate_count=0;
for(j=0;output_str[j]!='\0';j++)
{
if(output_str[j]==input_str[i])
{
duplicate_count=1;
}

}
if(duplicate_count==0)
{
output_str[j]=input_str[i];
output_str[j+1]='\0';
}

}
printf("The Resultent out put string is : %s",output_str);
getch();
}

Is This Answer Correct ?    21 Yes 15 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / munesh sharma

char* removeDuplicate(char str[])//remove duplicate characters from a string,so that each character in a string is not repeating
{
int i = 0,j;
char ch;
printf("\nstr is %s",str);
while((ch = str[i++] )!= '\0')
{
j = i;
printf("\n----ch = %c----",ch);
while(str[j] != '\0')
{
printf("\n--------Checking whether %c = %c \n",str[j],ch);
if(ch == str[j])
{
printf("\n------------Yes");
while(str[j]!='\0')
{
printf("\nRemoving %c %d -- \n",str[j]);
str[j] = str[++j];
--i;

}

break;
}
printf("\n------------No");

//printf("\njj");
j++;
}
}

return str;
}

Is This Answer Correct ?    6 Yes 0 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / utsav kumar

#include<stdio.h>
main()
{
char s[50];
int i=0,j;
printf("enter character string:");
while((s[i]=getchar())!='\n')
{
for(j=0;j<i;j++)
if(s[j]==s[i])
i--;
i++;
}
printf("after removing the duplicates the string is:");
for(j=0;j<i;j++)
printf("%c",s[j]);
}

Is This Answer Correct ?    17 Yes 11 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / anbu

/Made few corrections...

int remove_duplicates(char *str)
{
int char_check=0;
int i,j;
char ch;

char filterstr[256]; // new

if(str == NULL)
return 0;

/* check from 1st character in the string */
while(str[char_check]) {

ch = str[char_check];

i = j = char_check+1;

filterstr[0] = str[0]; // added

/* logic to remove the repeated character */
while(str[i]) {
if(str[i] != ch) {
filterstr[j] = str[i]; //modifid
j++;
}
i++;
}
filterstr[j]='\0'; //modified

str = filterstr; //added

char_check++;
}
printf("String after removing duplicates : %
s\n",filterstr);
return 1;
}

Is This Answer Correct ?    13 Yes 9 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / mbm

char *remove_duplicates(char *str)
{
char *str1, *str2;

if(!str)
return str;

str1 = str2 = str;

while(*str2)
{
if(strchr(str, *str2)<str2)
{
str2++;
continue;
}

*str1++ = *str2++;
}
*str1 = '\0';

return str;
}

Is This Answer Correct ?    15 Yes 12 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / migf1

char *s_stripdups( char *s )
{
register char *cp1 = NULL; /* for parsing the whole s */
register char *cp2 = NULL; /* for keeping desired *cp1's */
int used[256] = {0}; /* ascii boolean map, for used chars */

/* sanity checks */
if ( !s ) {
errno = EFAULT;
return NULL;
}
if ( !*s ) {
errno = EINVAL;
return s;
}

for (cp1=cp2=s; *cp1; cp1++ )
{
if ( 0 == used[(int)(*cp1)] ) { /* 1st occurence of *cp1 */
*cp2++ = *cp1; /* copy it to start of s, via cp2 */
used[(int)(*cp1)] = 1; /* mark it as used */
}
}
*cp2 = 0; /* null terminate the trimmed s */

return s;
}

Is This Answer Correct ?    1 Yes 1 No

To Write a C program to remove the repeated characters in the entered expression or in entered cha..

Answer / surya

Please send some important programming asked by product companies
to this mail id suryabharathi8@gmail.com

by
Surya

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4

2 Answers   HCL,


main() { int a[10]; printf("%d",*a+1-*a+3); }

1 Answers  


main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }

6 Answers  


Who could write how to find a prime number in dynamic array?

1 Answers  


3) Int Matrix of certain size was given, We had few valu= es in it like this. =97=97=97=97=97=97=97=97=97=97=97 1 = | 4 | | 5 | &= nbsp; | 45 =97=97=97=97=97=97=97=97=97=97=97 &n= bsp; | 3 | 3 | 5 | = | 4 =97=97=97=97=97=97=97=97=97=97=97 34 |&nbs= p; 3 | 3 | | 12 | &= nbsp; =97=97=97=97=97=97=97=97=97=97=97 3 | &nbs= p; | 3 | 4 | = | 3 =97=97=97=97=97=97=97=97=97=97=97 3 | = ; | | | = ; 3 | =97=97=97=97=97=97=97=97=97=97=97 &= nbsp; | | 4 | = ; | 4 | 3 We w= ere supposed to move back all the spaces in it at the end. Note: = If implemented this prog using recursion, would get higher preference.

0 Answers   RoboSoft,


Program to Delete an element from a doubly linked list.

4 Answers   College School Exams Tests, Infosys,


How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw...

6 Answers   Microsoft, MSD, Oracle,


write a origram swaoing valu without 3rd variable

2 Answers  


#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d----%d",*p,*q); }

1 Answers  


main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }

2 Answers  


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


How do you write a program which produces its own source code as its output?

7 Answers  


Categories