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  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
Program to trim a given character from a string.
 Question Submitted By :: Sandeep Ambekar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Program to trim a given character from a string.
Answer
# 1
// 
// MAIN -- Program to Purge a given character from a string.
// I/P example: ./a.out Bangalore a
// -- 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;
}                               // end of main..
 
Is This Answer Correct ?    1 Yes 2 No
Sandeep Ambekar
 
  Re: Program to trim a given character from a string.
Answer
# 2
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char string[]="lhellolollla";
int i=0;
int count=0;
while(i<strlen(string))
{
	while(string[i+count]=='l')
		count++;
	string[i]=string[i+count];
	i++;
	
}
printf("%s",string);
}
 
Is This Answer Correct ?    3 Yes 0 No
Dj
 
 
 
  Re: Program to trim a given character from a string.
Answer
# 3
best of luck for tomorrow's test
 
Is This Answer Correct ?    0 Yes 0 No
Dj
 
  Re: Program to trim a given character from a string.
Answer
# 4
in above solution  while loop iterates for only 6 times
 
Is This Answer Correct ?    0 Yes 0 No
Dj
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
c programming of binary addition of two binary numbers  1
Binary tree traversing Qualcomm1
can we access one file to one directory?  1
for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable  2
a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static Which of the Following Statements are true w.r.t Bit-Fields A)a,b&c B)Only a & b C)Only c D)All Accenture2
char ch="{'H','I',0};printf("%s",ch);what is output Accenture9
1 232 34543 4567654 can anyone tell me how to slove this c question  3
7. Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture8
Why doesn't C have nested functions?  2
C program to perform stack operation using singly linked list  3
Write code for finding depth of tree Adobe1
how many argument we can pas in in a function CTS20
what does exit() do? Cadence3
how to find string length wihtout using c function?  4
Write a program for deleting duplicate elements in an array Subex3
what are two categories of clint-server application development ?  1
what is the output of the following program? main() { int c[]={2,8,3,4,4,6,7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf("%d",*c); ++q; } for(j=0;j<5;j++) { printf("%d",*p); ++p; } }  4
We can draw a box in cprogram by using only one printf();& without using graphic.h header file? NIIT3
What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value. TCS7
what is the difference between entry control and exit control statement?  2
 
For more C 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