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

* strcspn( char str, char reject) - return the length of the initial segment of

ID: 3598030 • Letter: #

Question

* strcspn( char str, char reject) - return the length of the initial segment of str' which consists of characters entirely of characters that are not in reject. Example: strcspn( abc123", "d2" should return 4, because "abc1" does not contain "d2" e char* mstrcat char dest, char src) It will malloc a new block of enough size and store in it the concatenation of src and dest. The old dest will also be freed, so it is assumed that dest was allocated with malloc or strdup before calling mstrcat. Mstrcat will return the new block with the concatenation of dest and src. . strpbrk(char * str, char . accept)--function locates the first occurrence in the string str of any of the characters in the string accept. Returns a pointer in str to the first occurrence Returns null if no such character is found

Explanation / Answer

int strcspn1(char *str, char *reject){

int strSize = strlen(str);

int rejectSize = strlen(reject);

int answer = 0;

int flag = 0;

for(int i = 0; i < strSize; i++){

for(int j = 0; j < rejectSize; j++){

if(str[i] == reject[j]) {

flag = 1;

break;

}

}

if(flag == 0){

answer++;

}else{

break;

}

}

return answer;

}

char* mstrcat1(char *dest, char *src){

int destSize = strlen(dest);

int srcSize = strlen(src);

  

char *concatenationString = (char *) malloc (destSize + srcSize);

for(int i = 0; i < srcSize; i++){

concatenationString[i] = src[i];

}

  

for(int i = 0; i < destSize; i++){

concatenationString[srcSize + i] = dest[i];

}

  

printf(" ");

for(int i = 0; i < destSize + srcSize; i++){

printf("%c",concatenationString[i]);

}

return concatenationString;

}

char* strpbrk(char *str, char *accept){

int strSize = strlen(str);

int acceptSize = strlen(accept);

int position;

int flag = 0;

int j = 0;

  

for(int i = 0; i < strSize; i){

for(int j = 0; j < acceptSize; j++){

if(str[i] == accept[j]){

position = i;

flag = 1;

break;

}

}

if(flag == 1){

char *ret = (char *) malloc (strSize - position + 1);

for(int i = position; i < strSize; i++){

ret[j] = str[i];

}

return ret;

}

}

if(flag == 0){

return NULL;

}

}