Question

Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two strings while ignoring the ca
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here you go.

#include <bits/stdc++.h>

using namespace std;

int compare(char *a, char *b){

cout << a << " dsakl\n" << b << "\n";

// Converting upper case letters to lower case letters using ascii values
for (int index = 0; a[index]!='\0'; index++) {
if(a[index] >= 'A' && a[index] <= 'Z') {
a[index] = a[index] + 32;
}
}

// Converting upper case letters to lower case letters using ascii values
for (int index = 0; b[index]!='\0'; index++) {
if(b[index] >= 'A' && b[index] <= 'Z') {
b[index] = b[index] + 32;
}
}

// Built-in String Compare function
if(strcmp(a,b) == 0){
//printf("1Strings are the same\n");
return 1;
}
else {
//printf("1Strings are NOT the same\n");
return 0;
}
}

int main()
{
  
char a[1000], b[1000];

cout << "First string: ";
//Scaning string along with spaces
scanf("%[^\n]%*c", &a);

cout << "Second string: ";
//Scaning string along with spaces
scanf("%[^\n]%*c", &b);

int comp = compare(a, b);

// Built-in String Compare function
if(comp == 1){
cout << "Strings are the same\n";
}
else {
cout << "Strings are NOT the same\n";
}
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator...

    in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator class with the following 3 overloaded compare methods: 1. boolean compare(int a, int b): Return true if int a = int b, otherwise return false. 2. boolean compare(string a, string b): Return true if string a = string b, otherwise return false. 3. boolean compare(int[] a, int[] b): Return true if both of the following conditions hold true: O Arrays a and b are...

  • must be done in C Write a program that uses function strncmp to compare two strings...

    must be done in C Write a program that uses function strncmp to compare two strings input by the user. The program should input the number of characters to be compared, then display whether the first string is less than, equal to, or greater than the second string.

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    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...

  • Write a function that takes two arguments, both strings. Print "YES" if the second string argument...

    Write a function that takes two arguments, both strings. Print "YES" if the second string argument contains only characters found in the first string argument. Print "NO" if the second string argument contains characters not in the first. Here are some sample calls. In your program, call the function 3 times with the same arguments shown below. makeStr("hello", "") makeStr("hello", "olleloheloeloheloel") makeStr("hello", "olleloheloteloheloel") # YES # YES # NO

  • Python code Write a program that will ask the user to input two strings, assign the...

    Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)

  • Write a program thet uses the function strcmp() to compare two strings input by the user....

    Write a program thet uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less then, equal to, or greater then the second string 7. Write a program thet uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less then, equal to, or greater then the second string

  • C programming Write the implementation for the three functions described below. The functions are called from...

    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...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT