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 if they are identical.
c) Write a is_palindrome function. The function is required to be case insensitive and should only consider the letters and the numbers in the input string, i.e., remove all fillers (see lecture slides). Using this definition, the string “Madam, I’m Adam!” is considered a palindrome. The function is required to return 1 if the string is a palindrome and otherwise 0.
void print_string(char str[]);
int is_identical(char str1[],char str2[]);
int is_palindrome(char str[]);
void main(){
char str1[] = "Hello World";
char str2[] = "Madam, I'm Adam!";
char str3[] = "hello world";
print_string(str1);
#include<stdio.h>
#include<string.h>
#include <ctype.h>
void print_string(char str[]);
int is_identical(char str1[],char str2[]);
int is_palindrome(char str[]);
int main()
{
char str1[] = "Hello World";
char str2[] = "Madam, I'm Adam!";
char str3[] = "hello world";
printf("str1 : ");
print_string(str1);
printf("str2 : ");
print_string(str2);
printf("str3 : ");
print_string(str3);
if( is_identical( str1, str3 ) )
printf("str1 and str3 are identical.\n");
else
printf("str1 and str3 are not identical.\n");
if( is_palindrome( str2 ) )
printf("str2 is palindrome.\n");
else
printf("str2 is not palindrome.\n");
return 0;
}
void print_string(char str[])
{
int i;
// traverse the string
for( i = 0 ; i < strlen(str) ; i++ )
printf("%c", str[i]);
printf("\n");
}
int is_identical(char str1[],char str2[])
{
// if the length of two string are not equal
if( strlen(str1) != strlen(str2) )
return 0;
int i;
// traverse the string
for( i = 0 ; i < strlen(str1) ; i++ )
{
// if the current characters are not equal
if( tolower(str1[i]) != tolower(str2[i]) )
return 0;
}
return 1;
}
int is_palindrome(char str[])
{
int i, index = 0;
// to store the characters with only letters in small case
char temp[strlen(str)];
for( i = 0 ; i < strlen(str) ; i++ )
{
// isalpha() checks if character is alphabet
if( isalpha(str[i]) )
// store the lower case
temp[index++] = (char)tolower(str[i]);
}
// terminate the string
temp[index] = '\0';
// travesre half the string
for( i = 0 ; i < strlen(temp) / 2 ; i++ )
{
// if the i th character from beginning and ending are not equal
if( temp[i] != temp[strlen(temp) - i - 1] )
return 0;
}
return 1;
}
Sample output

C programming Write the implementation for the three functions described below. The functions are called from...
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...
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...
You are to implement a MyString class which is our own limited implementation of the std::string Header file and test (main) file are given in below, code for mystring.cpp. Here is header file mystring.h /* MyString class */ #ifndef MyString_H #define MyString_H #include <iostream> using namespace std; class MyString { private: char* str; int len; public: MyString(); MyString(const char* s); MyString(MyString& s); ~MyString(); friend ostream& operator <<(ostream& os, MyString& s); // Prints string MyString& operator=(MyString& s); //Copy assignment MyString& operator+(MyString&...
Using C++ Use the below program. Fill in the code for the 2 functions. The expected output should be: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: #include #include #include using namespace std; //Assume a line is less than 256 //Prints the characters in the string str1 from beginIndex //and inclusing endIndex void printSubString( const char* str1 , int beginIndex, int endIndex ) { } void printWordsInAString( const char* str1 ) { } int main() { char str1[] = "The fox jumps over the...
C Programming Language only please. Your help is greatly
appreciated. Will give thumbs up for quality work.
Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...
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...
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,...
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,...
Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with a new string. * Append an s to the end of your input string if it's not a keyword. * Insert a period at the end, if you have an empty input string do not insert a period Problems: //Why does my code stop at only 2 input strings //If I insert a character my empty string case works but it's still bugged where...