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
A: It allows a program to reference an identifier in global scope which has been hidden by another identifier along with the same name in the local scope.

Friend for Overloading Operators Sometimes friend functions cannot be avoided. For example with the operator overloading. Consider the following class that have data members to

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

A: auto: the default. Variables are created and initialized automatically while they are defined and destroyed at the ending of the block containing their definition. They are not

manupulates operator precidence

I have a program and I want someone to fix it for me by using basic c language program.

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

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

1. write a program named InputMethodDemo2 that eliminates the repetitive code in the InputMethod() in the InputMethodDemo program. Rewrite the program so the InputMethod()contains

Question 1 What are the different steps in executing a C program? Explain Question 2 What are the commonly used input/output functions in C? How are they accessed?