Execution of string length using pointer hopping, C/C++ Programming

A: #include

// Test to see if pointer hopping is worthwhile.

// strlen implemented with usual indexing mechanism. int strlen1( const char str[ ] )

{

int i;

for( i = 0; str[ i ] != '\0'; i++ )

;

return i;

}

// strlen implemented with pointer hopping. int strlen2( const char *str )

{

const char *sp = str;

while( *sp++ != '\0' )

;

return sp - str - 1;

}

// Quick and dirty main int main( )

{

char str[ 512 ];

cout << "Enter strings; use EOF-marker to terminate: " << endl;

while( cin >> str )

{

if( strlen1( str ) != strlen2( str ) )

cerr << "Oops!!!" << endl;

}

return 0;

}

 

Posted Date: 3/21/2013 7:31:43 AM | Location : United States







Related Discussions:- Execution of string length using pointer hopping, Assignment Help, Ask Question on Execution of string length using pointer hopping, Get Answer, Expert's Help, Execution of string length using pointer hopping Discussions

Write discussion on Execution of string length using pointer hopping
Your posts are moderated
Related Questions
Compiler Design - Limit In The Method Instructions

Jewels can only be removed for polishing from either end of the necklace

Objects as Function Arguments: In C program there are several methods to define arguments, and in some case even a structure can be approved as an argument.  Similarly in C+

I have to add virtual void calculatePay and virtual void displayEmployee. How to I implement that in Salaried and Hourly Employee?

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

Hello I''m new to programming, and I''m making now my 1st program. My question is how to put substr in textbox that question mark should be at the end of sentence? And 2nd question

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

I need website Product section search box coding section fix Project Description: On our products section in the search box it only searches the name and title of our product

A: this is a procedure during exception handling while the destructor is called for all local objects in the stack among the place where the exception was thrown & where this is ca

What is default constructor? explain it.