C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work.
#include<stdio.h>
//method to find lenght of str
int computeLength(char *str)
{
int i=0;
while(str[i]!='\0')//runs upto end of the string
i++;
return i;//returning length
}
//method to find prefix
int isPrefix(char *str1,char *str2)
{
int i=0;
while(str2[i]!='\0')
{
if(str1[i]==str2[i])
i++;
else
break;//if not prefix
}
int n= computeLength(str2);
if(i==n)//means prefix
return 1;
return 0;//other wise returning 0
}
int isPalindrome(char *str)
{
int n =computeLength(str);
int i=0,j=n-1;
while(i<n)
{
if(str[i]==str[j])
{
i++;
j--;
}
else break;
}
if(i==n)return 1;//if palindrome
return 0;
}
int main()
{
char str1[100],str2[100];
printf("Enter string 1:");
scanf("%s",str1);
if(computeLength(str1)<=1)
return 0;//terminations program if length =1
printf("Enter string 2:");
scanf("%s",str2);
if(computeLength(str2)==0)
return 0;//terminations program if length
=1
if(isPrefix(str1,str2)==1)printf("Prefix\n");
else printf("Not a prefix\n");
if(isPalindrome(str1)==1)printf("Palindrome\n");
else printf("Not a palindrome\n");
return 0;
}
output:
Enter string 1:amma
Enter string 2:am
Prefix
Palindrome
Process exited normally.
Press any key to continue . . .
C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...
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...
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. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) 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...
Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...
For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...
PLEASE USE MATLAB This is a basic problem that illustrates the concept of strings. A palidrome is a string of characters that is read the same forwards as it is backwards. For example, racecar' is a palindrome; reversing the order of the characters leaves the string unchanged. Write a otherwise. function called isPalindrome that accepts one input and returns one output. The input str is a string of characters, and the output is 1 if str is a palindrome, For...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...
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...
From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a Function that passes in a C-String and using a pointer determine the number of chars in the string. Data: “This is a test string for string length” Prt String Backwards: Write a Function that passes in a C-String and prints the string backwards. Data: “This is a test string for string backwards” replaceSubstring: Write a Function that accepts three C-Strings – str1,...
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,...
Need help writing this lab. Directions in lab attachment above. Thank you. Output should look like ones in attachment ab Ass Part 1 sing Static Arra Do this part on your own. Write a program named lab11 a.c containing the following function: preconditions arc is terminated by dest is big enough hold arc postconditions dest contains src and is terminated by "10" void my strcpy (char dest const char srclj) This function will take two character arrays as parameters. The...