Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Program in C++) Using only pointer notation, implement and test the following f

ID: 3882668 • Letter: #

Question

(Program in C++) Using only pointer notation, implement and test the following functions that operate on strings:

int strCmp ( const char *s1, const char *s2) returns 0 if s1 and s2 are the same; it returns-1 when s1 precedes alphanumerically s2 or it returns 1 when s1 follows alphabetically s2.   

char * strPbrk (const char*s1, const char*s2) scans s1 for the first occurrence of any character appearing in s2 and returns a pointer to its location or NULL if no such occurrence is found.

char* ItoA ( int n, char*s) converts an integer n into string of numerals stored in s and returns s.

Explanation / Answer

The desired program in c++ is given below:

#include<iostream>
    #include<stdio.h>
    using namespace std;
    int strCmp(const char*, const char*);
     const char* strPbrk(const char *s1, const char *s2);
    main() {
       char string1[50],string2[50];
       cout<<"Enter string first:";
       gets(string1);
       cout<<"Enter string second:";
       gets(string2);
       if(strCmp(string1,string2))
                cout<<"These are equal string"<<endl;
       else
                cout<<"These are not equal string"<<endl;
              
       cout<<"The first occurance in s1 is character: "<<*(strPbrk(string1,string2));
       return 0;
    }
    int strCmp(const char *s1, const char *s2) {
       while(*s1==*s2) {
      
           s1++;
           s2++;
       }
       if(*s1==' '&&*s2==' ')
                return 0;
       return 1;
    }
  
    const char* strPbrk(const char *s1, const char *s2)
    {
      
       while(*s1 != *s2)
       {
           s1++;
           s2++;
       }
       if(*s1 == *s2)
       {
           return (s1);
       }
       else
       {
           return NULL;
       }
      
   }