74.4k views
1 vote
With an example in each, describe the use of two basic functions which are known by the "string.h" header file.

User Hjrshng
by
6.8k points

1 Answer

7 votes

Answer:

strcmp(char * A, char * B);

strcat(char * A, char * B)

Step-by-step explanation:

One of these basic functions is the function strcmp(char * A, char * B).

This functions compares if two strings are equal; If they are, it returns 0. If not, it returns 1;

So, an example:

char A[13] = "Buffalo Bills";

char B[13] = "Buffalo Bills";

if (strcmp(A,B) == 0)

printf("The strings are the same\\);

else

printf("The strings are not the same");

In this case, they are the same.

----------------------

If for example:

char B[13] = "Buffalo Billz"

It would fall in the else, A and B would not be the same strings.

--------------------------

Other function is the strcat(char * A, char * B);

This function takes two strings as an input, and concatenate them to the first.

For example:

char A[15] = "Buffalo";

char B[5] = "Bills";

strcat(A, B);

printf("%s\\", A);

The output is:

Buffalo Bills

User AmeliaMN
by
6.1k points