using c,
Write a function called p4. The function takes 2 parameters, both of which are C strings. p4 should return “true” (not 0) if the 2ndparameter is a substring of the 1st parameter, or “false” (0) otherwise. Forexample:
char topic[] = “computer”;
char substr[] = “put”;
printf(“%d\n”, p4(topic, substr); // prints 1
substr[0] = ‘P’;
printf(“%d\n”, p4(topic, substr); // prints 0 – case sensitive char
s1[] = “ababcd”;
char s2[] = “abcd”
char s3[] = “baba”;
char s4[] = “baba”;
printf(“%d %d\n”, p4(s1,s2), p4(s1,s3)); // 1 0printf(“%d\n”,
p4(s3,s4)); // 1
#include <stdio.h>
#include <stdbool.h>
int p4(const char s[], const char t[]){
int i = 0,j = 0;
while(s[i]!='\0' && t[j]!='\0'){
if(s[i] == t[j]){
j++;
}
else{
j = 0;
}
i++;
}
if(t[j] == '\0'){
return true;
}
else{
return false;
}
}
int main(void) {
char topic[] = "computer";
char substr[] = "put";
printf("%d\n", p4(topic, substr));
substr[0] = 'P';
printf("%d\n", p4(topic, substr));
char s1[] = "abcd";
char s2[] = "baba";
char s3[] = "baba";
printf("%d %d\n", p4(s1,s2), p4(s2,s3));
return 0;
}


using c, Write a function called p4. The function takes 2 parameters, both of which are...
Note that the main function that I have provided does use <string.h> as it constructs test strings to pass to your functions. However, your solutions for the 5 functions below may not use any of the built-in C string functions from the <string.h> library. Write a function called strcmp373. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not *...
CSC Hw Problems. Any help is appreciated I dont know where to start let alone what the answers are. Your assignment is to write your own version of some of the functions in the built-in <string.h> C library. As you write these functions, keep in mind that a string in C is represented as a char array, with the '\0' character at the end of the string. Therefore, when a string is passed as a parameter, the length of the...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
****Using c++ (Check Substrings) Write the following function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. int indexOf(const string& s1, const string& s2) Write a test program that reads two strings and checks whether the first string is a substring of the second string.
In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...
Write a function definition for a function my_strcmp() with the
following header:
Write/Implement a function definition for a function my_strcmp () with the following header: int my_strcmp (const char *s1, const char *s2) This function compares the string pointed to by s1 to the string pointed to by s2. If the string pointed to by s1 comes before the string pointed to by s2 in dictionary ordering, then -1 is returned. If the string pointed to by s1 is the...
Write a python function alt which takes a list of strings myList as a parameter. alt then returns two strings s1 and s2 as a tuple (s1, s2). Here s1 is the concatenation of the strings in myList in even index positions, and s2 is the concatenation of the strings in myList in odd index positions. (List starts at index 0) For example, if myList = [‘My’, ‘kingdom’, ‘for’, ‘a’ , ‘horse’], then s1 = ‘Myforhorse’ and s2 = ‘kingdoma’.
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
We want to write a function called sortTwo that takes two integer parameters, and after the function is called the first parameter is the smaller of the two values, and the second parameter is the larger of the two values. In other words, this is a miniature sorting function. For this problem you must supply the missing code for PARTs 1, 2, and 3 in the program below. // PART 1: function prototype int main ( ) { int x,y;...
Write a function called printStars. The function receives a parameter containing an integer value. If the parameter is positive, the funciton prints (to standard output) the given number of asterisks. Otherwise the function does nothing. The function does not return a value. Thus, if printStars(8) is called, ******** (8 asterisks) will be printed. The function must not use a loop of any kind (for, while, do-while) to accomplish its job. Instead, it should examine its parameter, returning if the parameters...