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
Static Data Members: A data member inside the class can construct as static data member.   There are few guidelines to be followed when declaring static data member.

The program must use the file named on the command line as its input file. Suppose the program is named pdbtool. Then if the user types pdbtool 1A36.pdb the program must read the d

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area

Question: (a) What is a function? Are functions needed when writing a C program? (b) State one of the advantages to the use of functions. (c) What do you meant by underst

What is abstraction? - Simplified view of an object in user's language is termed as abstraction. - It's the simplest, well-defined interface to an object in OO and C++ which

replace character into string and return value of string that are replaced

Want an EA project for Jack Bsher Project Description: New EA game Skills required   Android, C++ Programming, PHP, Metatrader, SQL

Write a method (belonging to the TermStructure class) that takes a pointer to an array of bonds and an integer, representing the number of bonds in the array as arguments, and esti

A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin

Program to show the ascii value of characters: int main() {                 int one_char;                 cout                 one_char = getch();