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) Verify the values of the resistors with the following colour coding: (i) red-red-orange-silver (ii) orange-orange-black-blue-green (b) What is the value of a resistor

There are 3 acceptable answers: "Never," "Rarely "and" When the problem domain cannot be accurately modelled any other way."

Define a structure to store roll no, name and marks of a student. b) Using the structure of Q2. a), above write a ''C'' program to create a file "student.dat". There must be one r

Question: a) Give two uses of NFS. b) Give one advantage of using NFS. c) Explain the following lines as they would be interpreted in the /etc/exports file i. /usr/local

# include stdio.h> # include string.h> # include conio.h> void main()   {           int i=0,count=0;           char a[100],b;           clrscr();

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

given number is prime or not

Part 1 Assignment:  develop a calculator in MASM. Text chapters covered:  1 through 4, 5.4, 5.5, 6.3, 7.4 You will develop a "calculator" algorithm in MASM using reverse-

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

Webcam Driver static library or DLL required for Windows I want a .dll or .lib file using which i will take a snapshot from the webcam and it can't turn on the webcam LED while