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
what is local and global variable?give me some example to understand better

Rahul is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''{'' and end with '

program to convert string from super ascii string with minimum cost

Aim: To implement a program to convert time in 24 hour format to 12 hour format. Code:                       #include #include #include class time24 {

overload assignment opertor to assign the data of one object to anthor

Conversion Functions Conversion functions are member functions used for the following purposes: 1. Conversion of object to basic data type. 2. Conversion of basic data ty


Your task is to create a programming system for a ferry. The ferry transports passengers and vehicles (cars, busses, lorries and bicycles). The ferry has space for 200 passengers a

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro

You are working for a computer gaming company and have been asked to look at a survival game.  You will be simulating a rabbit stranded on an island, collecting a large number of s