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

Assignment Help:

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;

}

 


Related Discussions:- Execution of string length using pointer hopping

Explain about the unions, Explain what are Unions? The Unions like as s...

Explain what are Unions? The Unions like as structures, contain members whose individual data types may perhaps differ from one another. Though the members that create a union

Array, how to use nested loop of for in array

how to use nested loop of for in array

Describe "this" pointer?, It is a pointer accessible only in the member fun...

It is a pointer accessible only in the member functions of a struct, class or union type. It points to the object for which the member function is called. Static member functions d

Is it possible to pass an entire structure to functions, Is it possible to ...

Is it possible to pass an entire structure to functions? Yes, it's possible to pass an entire structure to a function in a call by method style. Some programmers prefer to decl

Facebook auto like system, I want a PROGRAM - Facebook auto like system to ...

I want a PROGRAM - Facebook auto like system to increase fans to different fanpage It has in a program that take Facebook mails and passwords from a excel file (.xlsx) for examp

Functions, write a program to calculate gross salary and net salary using h...

write a program to calculate gross salary and net salary using hra da pf in c++

How does free know the size of memory to be deleted.?, How does free know t...

How does free know the size of memory to be deleted.? int *i = (int *)malloc(12); followed by free(i); how did free function call know how much of memory to delete? A: It bas

Program for read a formal expression from standard input, Your program will...

Your program will read two kinds of data from two files: names and predicates. It will read a formal expression from standard input and check whether that expression is syntactical

Write short note on classes in c++, Introduction to Classes Object-orie...

Introduction to Classes Object-oriented programming (OOP) is a conceptual approach to design programs. It can be executed in many languages, whether they directly support OOP c

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd