Question

Write a C function that takes two strings (character arrays) as input and return 1 if...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
int equalornot(char[],char[]);
int main()
{
char str1[100],str2[100];
printf("Enter a string1: ");
gets(str1);
printf("Enter a string2: ");
gets(str2);
int res;
res=equalornot(str1,str2);;
if(res==1)
printf("Strings are equal.");
else
printf("Strings are not equal.");
return 0;
}
int equalornot(char str1[], char str2[])
{
int i,len1=0,len2=0,count=0;
for(i=0;str1[i]!='\0';i++)
len1++;
for(i=0;str2[i]!='\0';i++)
len2++;
if(len1!=len2)
return 0;
else
{
for(i=0;str1[i]!='\0';i++)
{
if(str1[i]==str2[i])
count++;
}
if(count==len1)
return 1;
else
return 0;
}
}

Add a comment
Know the answer?
Add Answer to:
Write a C function that takes two strings (character arrays) as input and return 1 if...
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 C function that takes two strings (character arrays) as input and return 1 if...

    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.

  • 2. Write a function convstrs that will receive a cell array of strings and a character...

    2. Write a function convstrs that will receive a cell array of strings and a character (either 'U' or 'L') as input arguments. If the character is 'U', it will return a new cell array with all of the strings in uppercase. If the character is 'L', it will return a new cell array with all of the strings in lowercase. If the character is neither 'U' nor 'L', or if the cell array does not contain all strings, the...

  • MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...

    MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.

  • write a function which takes a string argument and a character argument. It should return a...

    write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...

  • Write a function that takes an array of C-strings as a parameter and the number of...

    Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

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

  • Write a method that takes two arrays of integers and return and array that is the...

    Write a method that takes two arrays of integers and return and array that is the union of both arrays. For instance, the first array contains (1,2,3), the second array(4,5,6), the returned array should contain (1,2,3,4,5,6) (3.5 points) Write a method that takes and an array and return the reverse of that array. For instance, if the array is (1,2,3), the returned array should be (3,2,1) (3.5 points)

  • Declare a function that checks whether two strings are equal. In function main, read two strings,...

    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

  • Write a function named words_in_both that takes two strings as parameters and returns a set of...

    Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". The file must be named: words_in_both.py...

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