Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

How to write a function that goes through an array of
characters and eliminates any elements that are not letters
(Legal letters can be either in an uppercase or a
lowercase format.)
The function removeNonLetters should return the new
effective size of the array as the result.

Answers were Sorted based on User's Feedback

How to write a function that goes through an array of characters and eliminates any elements that ..

Answer / vivek

//This function returns true if valid character, else false
bool isCharacter(char unknownCharacter)

//Check whether the character falls between
// a ...z or A....Z
if( (unknownCharacter >= 'a' &&
unknownCharacter <= 'z') ||
unknownCharacter >= 'A' &&
unknownCharacter <= 'Z')

return true;


return false;



//This function removes non characters and returns array s
//effective size.
unsigned int removeNonCharacters(char *charArray, unsigned int arraySize)

//Lets decrement by non character as and when we identify
unsigned int effectiveArraySize = arraySize; .

//Algo: Traverse the array and in the mean time Identify
// non chars positions and move valid chars from right
// side of the array to fill those positions.

//used to traverse and mark valid chars.
unsigned int currentValidCharacterPosition = 0;

//Used to traverse and mark non valid character
unsigned int currentNonValidCharacterPosition = 0;

while( (currentValidCharacterPosition < arraySize) &&
(currentNonValidCharacterPosition < arraySize) )

if(isCharacter(charArray[currentValidCharacterPosition ])

//If we are here mean this is a valid character in
//the array, go to next character


else //This is a non character
//Mark the first non valid character position
currentNonValidCharacterPosition =
currentValidCharacterPosition ;

//move to findout valid character in the remaining
while( (currentValidCharacterPosition <= arraySize) && (!isValidCharacter(characterArray[currentValidCharacterPosition]) )


}//End While

//Check in the mean time whether we exhausted the
if( currentValidCharacterPosition == arraySize)

return effectiveArraySize;

}//End If

//Move the valid character to fill the leftmost
//non valid character position.
= characterArray[currentValidCharacterPosition];

//Move on.

}//End Else (invalid character)

}//End While

return effectiveArraySize;

Is This Answer Correct ?    0 Yes 0 No

How to write a function that goes through an array of characters and eliminates any elements that ..

Answer / vivek

Please bear with indentation, treat charArray and characterArray as same.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More STL Interview Questions

Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A.Explain how a pointer to function can be declared in C++? B.List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header (“Include”) Files.

0 Answers   GE, Infosys, Microsoft, NIM,

how to overload << and >> operator in c++

3 Answers   Wipro,

write a program to demonstrate,how constructor and deconstructor work under multilevel inheritance

3 Answers   TCS,

method overloading means what?

2 Answers   CTS,

What is stl in c++ with example?

0 Answers  

write a program that input four digit no and finds it is palindrome or not

2 Answers  

what is an algorithm in terms of STL?

1 Answers   Lucent, Wipro,

Why should a c++ programmer be interested in stl?

0 Answers  

Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts

0 Answers  

Is stl part of c++ standard?

0 Answers  

what is template and type convertion

0 Answers   TATA,

Explain when u will use Observer pattern and how u will implement in c++ .

1 Answers