Question

3. Look up the man pages for the following string functions from the C standard library,...

3. Look up the man pages for the following string functions from the C standard library, and write implementations of each:

  • strcmp()

Please explain your answer, thank you

Homework Answers

Answer #1

Solution

#include <stdio.h>

int strcmp(const char *S1, const char *S2)
{
while (*S1)
{
if (*S1!= *S2)
break;

S1++;
S2++;
}

return *(const unsigned char*)S1- *(const unsigned char*)S2;
}


int main()
{
char *A = "Student";
char *B = "Stand";

int cmp = strcmp(A, B);

if (cmp > 0)
printf("%s is greater than %s. Character in %s is lexicographically after the character of %s",A,B,A,B);
else if (cmp < 0)
printf("%s is less than %s. Character in %s is lexicographically before the character of %s",A,B,A,B);
else
printf("%s is equal to %s",A,B);
return 0;
}

Code Screenshot

Output

Know the answer?
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
Similar Questions
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: intQ1_for() intQ1_while() intQ1_do() To compute the sum of all numbers that are multiples of 4, between 30 and 1000, in 3 different ways: with a for loop, a while loop and a do-while loop, accordingly. After each loop print the value. Return the total sum at the end of each...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: Calculate the value of π from the infinite series: π = 4 – 4/3 + 4/5 – 4/7 + 4/9 – 4/11 + … Complete the double Q4(intQ4_input) function which reads a positive integer Q4_input as an input parameter and calculates the value of π by adding up the first...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: a) Complete the int Q7a(intQ7_input) function takes a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) For this exercise you should be able to write a logical expression (i.e., with logical operators) which checks if some integer x consists of exactly 5 digits. Ex: 30498 and -14004 are 5-digit numbers, while 1018, -2 and 46 are not. Complete the intQ2(intQ2_input) function that takes an input integer parameter and returns 1 if the number is...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following function using C programming language: Complete the function intQ3(floatQ3_input) that takes a student’s average as an input, which is a floating-point value, and returns: 4 if the average is in the range 90-100, 3 if it is in the range 80-89, 2 if it is in the range 70-79, 1 if it is in the...
PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int...
PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int q3(int x) {     return ((~x)>>31) & 0x1; } int q4(int x) {     int mask = x>>31;     int y= (x ^ mask);     int z = (~mask + 1);     return (y+z); } int q5(int x){     int y = !x;     int z = x >> 31;     z = z | y;     return !z; } int q6(int x) {...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: A positive integer number is said to be a perfect number if its positive factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6=1+2+3. Complete the int Q6(intQ6_input, int perfect[])function that determines all perfect numbers smaller than or equal...
String array operations a. Create a string array called myInformationcontaining the following entries in order: Your...
String array operations a. Create a string array called myInformationcontaining the following entries in order: Your full name The name of the town or city where you were born Your major The name of this university with only the first letter of each word capitalized; don’t forget the “The”! b. Use the Matlab function strcmp to compare the name of the university as you defined it against the following two strings: i. “The Ohio State University” ii. “THE OHIO STATE...
3. Look up the Gram reaction and morphology of the following four organisms and type the...
3. Look up the Gram reaction and morphology of the following four organisms and type the information next to each organism below. Bacillus cereus – Escherichia coli – Pseudomonas aeruginosa – Staphylococcus aureus – 4. In your own words, explain the difference between a broad-spectrum and a narrow-spectrum antibiotic.
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT