Page 1 of 1

Write the following function without using the C++ string class or any functions in the standard library, including strl

Posted: Sun May 15, 2022 1:52 pm
by answerhappygod
Write the following
function without using the
C++ string class or any functions in the
standard library, including strlen().
You may use pointers, pointer
arithmetic or array notation.
Write The Following Function Without Using The C String Class Or Any Functions In The Standard Library Including Strl 1
Write The Following Function Without Using The C String Class Or Any Functions In The Standard Library Including Strl 1 (284.74 KiB) Viewed 77 times
PE09 - C-String Functions Write the following function without using the C++ string class or any functions in the standard library, including strlen(). You may use pointers, pointer arithmetic or array notation. Write the function findFirstof(). • The function has two parameters (stri, str2), both pointers to the first character in a C-style string. • You should be able to use literals for each argument. • The function searches through stri, trying to find a match for the first occurance of the C-string pointed to by str2. Return the index inside strl where str2 occurs. • Note that if str2 does not appear in str1, then return - 1. Call the function like this: cout << findFirstOf("eieioh", "eio"); // prints 2 (the index of the second e) cout << findFirstOf("aaaiii", "aia"); // prints -1 (aia not inside aaaiii) In both cases the function returns the index of the first occurrence of str2 inside stri. Exam C++ Quick Reference pe09.cpp 1 #include <cstddef> 1/ size_t for sizes and indexes 2 using namespace std; 3 ITI WRITE YOUR FUNCTION BELOW THIS LINE MITT int findFirstof (const char * si, const char * s2) 5 { 6 int result; 7 // Add your code here 8 return result; 9} CodeCheck Reset