Question

FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const...

FOR C PROGRAMMING LANGUAGE

Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.

Homework Answers

Answer #1
#include <stdio.h>

int sumStrlens(const char *str1, const char *str2);

int main() {
    printf("%d\n", sumStrlens("Hello", "How are you?"));
    return 0;
}

int sumStrlens(const char *str1, const char *str2) {
    if (!(*str1)) {
        if (!(*str2)) {
            return 0;
        } else {
            return 1 + sumStrlens(str1, str2 + 1);
        }
    } else {
        return 1 + sumStrlens(str1 + 1, str2);
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ Coding Please. Thank you! 1) Complete a function, getStringInfo. Two given character strings are as...
C++ Coding Please. Thank you! 1) Complete a function, getStringInfo. Two given character strings are as below. char *str1 = “my name is Amy!”; char *str2 = “I got lost on my way to work”; The function accepts two constant character strings, str1 and str2 as pointer. Exchange the sentence of the variables str1 and str2 and then compute and display both strings’ length using pointer. Return the sum of the lengths of str1 and str2 int getStringInfo(const char *str1,...
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
How would I write this function in C programming language? Function header: int input(int *a, int...
How would I write this function in C programming language? Function header: int input(int *a, int *b, int *c) This function should attempt to input 3 integers from the keyboard and store them in the memory locations pointed to by a, b, and c. The input may not be successful in reading all three values. The function should return the number of values that were successfully read.
How would I write the following program in C programming language? Function header: int sumsort(int *a,...
How would I write the following program in C programming language? Function header: int sumsort(int *a, int *b, int *c) This function should arrange the 3 values in the memory locations pointed to by a, b, and c in ascending order and also return the sum of the contents of the memory locations a, b, and c.
Write a function to create a copy of a string with the prototype below. (C Language)...
Write a function to create a copy of a string with the prototype below. (C Language) char * strcpy (const char *); The function should dynamically allocate the necessary memory for the new string. You can do that with char * newstr = (char *) malloc(sizeof(char) * (strlen(str)+1)); assuming str is your input string. Think though how you would copy the characters of the string, and don't forget about the end of string character.
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
Write in Racket Language Write a recursive Racket function "sum" that takes two integers as parameters,...
Write in Racket Language Write a recursive Racket function "sum" that takes two integers as parameters, each greater or equal to zero, and evaluates to their sum. In this problem, you must use the built-in functions "add1" and "sub1" and may not use the built-in functions "+" or "-". For example, (sum 2 3) should evaluate to 5. Note: (add1 5) evaluates to 6 and (sub1 4) evaluates to 3. Hint: like you saw in the "append" lecture, treat one...
C++ please! Write a recursive function to compute the sum of the Taylor series. use double...
C++ please! Write a recursive function to compute the sum of the Taylor series. use double taylor(int a, int n)