Write a program for deleting duplicate elements in an array
Answers were Sorted based on User's Feedback
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 |
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 sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?
how to add numbers without using arithmetic operators.
4. main() { int c=- -2; printf("c=%d",c); }
write a program to sum of its digit with using control structure or with out using loop. for ex: let the number is 25634 then answer will be=2+5+6+3+4=20
How do you override a defined macro?
how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ?
#define d 10+10 main() { printf("%d",d*d); }
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
How can I check whether a file exists? I want to warn the user if a requested input file is missing.
Is c an object oriented programming language?
What is the difference between exit() and _exit() function?
How we add our function in liabrary as liabrary function. Exp. we want use our int factorical(int); function as int pow(int,int); function working in math header file.