Declare a function that checks whether two strings are equal. In
function main, read two strings, call the function and print
“equal” if the strings are equal and “not equal” otherwise. The
input strings contain at most 50 characters.
Example of input: alphabet alphabet Corresponding output:
equal
Example of input: week weak Corresponding output: not
equal
In C Language
Answer)
String comparison program:
#include <stdio.h>
int check_equal(char [], char []);
int main()
{
char string1[50], string2[50];
printf("Enter the first string: \n");
gets(string1);
printf("Enter the second string: \n");
gets(string2);
if (check_equal(string1, string2) == 0)
printf("Equal\n");
else
printf("Not Equal\n");
return 0;
}
int check_equal(char string1[], char string2[])
{
int i = 0;
while (string1[i] == string2[i]) {
if (string1[i] == '\0' || string2[i] == '\0')
break;
i++;
}
if (string1[i] == '\0' && string2[i] == '\0')
return 0;
else
return -1;
}
Output:
Enter the first string:
weak
Enter the second string:
week
Not Equal
Enter the first string:
week
Enter the second string:
week
Equal
Declare a function that checks whether two strings are equal. In function main, read two strings,...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...
(c++) Write a predicate function that checks whether two vectors have the same elements in the same order. Write a predicate function that checks whether two vectors have the same elements in the same order bool equals(vector<int> a, vector<int> b) provided code : #include <iostream> #include <vector> using namespace std; bool equals(vector<int> a, vector<int> b) { // TODO } int main() { // TODO // Print Expected, "Vectors a and b are " (print "equal." if they are. Otherwise, print...
Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b. Your FSM program should include the following three static methods (Java) or functions (C): a. int nextState(int state, char symbol) A state-transition function that returns the next state based on the current state and an input symbol. This function should also return -1 when an invalid input character is detected. State...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
Have the function wildcard(str) read str which will contain two strings separated by a space.The first string will consist of the following sets of characters: +, *, $ and {N} which is optional.The plus (+) character represents a single alphabetic character, the ($) character represents anumber between 1-9, and asterisk (*) represents a sequence of the same character of length 3unless it is followed by {N} which represents how many characters would appear in thesequence where N will be at...
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...
Write a C++ console application that reverses an array of characters, and counts the number of: Lower case characters (islower) Upper case characters (isupper) Digits (isdigit) Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...
Write a C function that takes two strings (character arrays) as input and return 1 if they are equal and return 0 if they re not. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal in the same order.
Write a C function that takes two strings (character arrays) as input and return 1 if they are equal and return 0 if they re not. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal in the same order.