ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
To Write a C program to remove the repeated characters in 
the entered expression or in entered characters(i.e) 
removing duplicates.
 Question Submitted By :: Selva
I also faced this Question!!     Rank Answer Posted By  
 
  Re: To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates.
Answer
# 1
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 ?    10 Yes 3 No
Tls
 
  Re: To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates.
Answer
# 2
#include <stdio.h>

main(int argc, char **argv)
{
  int i;
  char *source = argv[1];
  char *dest;
  char *temp;

  unsigned int bitmap[8] = {0,0,0,0,0,0,0,0};
  unsigned char c;
  unsigned int mask;

  dest = (char*)malloc(strlen(source));
  temp = dest;

  printf("before %s\n", source); 
  i=0;
  while(source[i])
  {
    c = source[i];
    mask = 1 << (c % 32);

    if ((bitmap[c/32] & mask) == 0) 
    {
      *temp++ = source[i];
      bitmap[c/32] |= mask;
    }
    i++;
  }

  *temp = '\0'; 
    
  printf("after %s\n", dest); 
}
 
Is This Answer Correct ?    4 Yes 5 No
Lijun Li
 
 
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }  1
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }  1
char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }  1
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];  1
how to check whether a linked list is circular.  3
What is "far" and "near" pointers in "c"...?  3
main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }  1
main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }  1
Program to Delete an element from a doubly linked list. Infosys4
Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };  1
#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }  1
What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }  1
How will u find whether a linked list has a loop or not? Microsoft6
Find the largest number in a binary tree Infosys4
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
What is the hidden bug with the following statement? assert(val++ != 0);  1
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }  1
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.  2
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }  1
main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com