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
write c++programm that converts degrees Kelvin (TK) to degrees Fahrenheit(TR) recall that TF=(9/5)TK and that TF=TR-459.67

Is it possible to create your own header files? - Yes, it's possible to create a customized header file. - To do this, you just need to include function prototypes that you


A container class is a class which is used to hold objects in external storage and memory. A container class work as a generic holder. A container class contains a predefined behav

I need Cryengine Sandbox Speedometer and Tachometer We want to get working Tachometer and Speedometer for a car in latest Cryengine Sandbox. You will find how to make it usin

write a promgram using object oriented peramid

Define Commonly Used Built-in Library Functions? Comprise opened a file pointer you will desire to use it for either input or output. The C language supplies a set of functions

Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? Becareful for the Leap year

1. Basic Heap: Each memory location in our model of the RAM will be an instance of type Memory: 2. typedef union Memory_u Memory; 3. union Memory_u{ 4. char character;

Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.