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

Write the function first Not ln (). The function has two parameters; const char

ID: 3826458 • Letter: W

Question

Write the function first Not ln (). The function has two parameters; const char * str and const char * chars. The first is the C - style string to search, and the second is a C - style string containing characters to exclude. The function returns the index (as a size_t) of the first occurrence of any character from str that does not appear inside chars. If all of the characters inside str appear inside chars, return the value size_t (-1). You cannot use any library functions for this problem. You may use array or pointer notation.

Explanation / Answer

#include<iostream>
using namespace std;
int firstNotIn(char *str, char *chars){
   int ind1,ind2;
   for(int i=0;i<30;i++){
       if(str[i]==NULL){
           ind1=i;
           break;
       }
   }
   for(int i=0;i<30;i++){
       if(chars[i]==NULL){
           ind2=i;
           break;
       }
   }
   cout<<"ind1 : "<<ind1<<" ind2: "<<ind2<<endl;
   for(int i=0;i<ind1;i++){
       for(int j=0;j<ind2;j++){
           if(str[i]==chars[j])
               return i;
       }
   }
   return -1;
}
int main(){
   char str[30];
   char chars[30];
   cout<<"Enter string : ";
   cin>>str;
   cout<<"Enter chars : ";
   cin>>chars;
   cout<<firstNotIn(str,chars);
   return 0;
}