Write a program for deleting duplicate elements in an array

Answers were Sorted based on User's Feedback



Write a program for deleting duplicate elements in an array..

Answer / sandeep ambekar

//
// MAIN -- Write a program for deleting duplicate elements in an array
// Example: # a.out string substr
// I/P example: ./a.out Bangalore a
//
// Author -- Sandeep Ambekar

#include <stdio.h>
#define TRUE 1
#define FALSE 0

void
purge_char_from_string (char *str, char *c)
{
int i, k, flag, count; // i/j for index, flag to
keep track of
// 'c' and count for iteration..
char *buf = str; // save the original string
start:
str = buf; // we could enter the loop
again.
i = 0;
k = 1;
count = 0;
flag = FALSE; // INIT variables...
printf ("Input String [%s] [%c] \n", str, *c);

while (str[i] != '\0')
{
printf ("\t (%c) <==> (%c)\n", str[i], str[k]);
if (str[i] == c[0])
{
str[i] = str[k];
flag = TRUE;
count++;
}
else if (flag == TRUE)
{
str[i] = str[k]; // later have a while loop
to find a char
// to which is !c and replace them.
}
i++;
k++;
}
printf ("[%s]\n", buf);
if ((count - 1) >= 1)
goto start;
} // end of
purge_char_from_string ....

//
// MAIN -- Program to Purge a given character from a string.
//

int
main (int argc, char *argv[])
{
if (argc < 3)
{
printf ("Input <String> <char> \n");
return 1;
}
printf (" ## Input string %s : Char [%s]\n", argv[1],
argv[2]);
purge_char_from_string (argv[1], argv[2]);

printf (" Trimmed String ---> %s\n", argv[1]);
return 0;
}

Is This Answer Correct ?    5 Yes 3 No

Write a program for deleting duplicate elements in an array..

Answer / bhanuprakash a

/* here is the actual logic */
for(i=1; i<n; i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i] = a[j])
{
for(k=j;k<n;k++)
{
a[k]=a[k+1]; //deletion
n=n-1;
}
}
}
}

Is This Answer Correct ?    7 Yes 8 No

Write a program for deleting duplicate elements in an array..

Answer / vrushali

Any program without goto.

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Interview Questions

What is int main () in c?

0 Answers  


Can we write a program without main() function?

9 Answers  


What is hashing in c language?

0 Answers  


What does c mean in standard form?

0 Answers  


What is the value of c?

0 Answers  






what is the c source code for the below output? 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1

0 Answers  


write a c program that if the given number is prime, and their rearrangement(permute) of that number is also prime. Ex: Input is "197" is prime Output: 791,917,179 is also prime. Please any one tell me tha code for that

3 Answers  


What is the difference between procedural and declarative language?

0 Answers  


a character variable can at a time store a) 1 character b) 8 characters c) 254 characters d) none of the above

3 Answers  


1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop

2 Answers  


how i m write c program 1.check prime number 2.prime number series

1 Answers  


Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.

8 Answers  


Categories