Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Help? Need help on some homework. Here are the questions... I am new to C++

ID: 3559531 • Letter: C

Question

C++ Help?

Need help on some homework. Here are the questions... I am new to C++ and this part has been giving me fits of issues... can anyone help me out with the following problems!? Would really appreciate it! Thanks!

1)Why does the program crash when it attempts to execute the strcat function?



2) What operation does the function strcpy perform? what does it do? What is the result?


3) What operation does the function strncpy perform? What does it do differently than strcpy? What is the result?


4)What operation does the function strcat perform?What does it do? What is the result?

5)What compiler warnings were given, if any? What do they mean?

Operation of the

Explanation / Answer

a) strcat function is used to concatinate two strings. Hence when we use strcat there should be proper memory spaces available after the first string.Whenever it does not get that, it gives an error.

b)strcpy function is used to copy 1 string into other.Suppose we have a character array a which contains some strings nad we need to copy it into another character array b.For this we do strcpy (a,b). This will perform the above mentioned action.

c) )strncpy function is used to copy 1 string into other from specific position which is mentioned as nth position..Suppose we have a character array a which contains a string "parameter"and we need to copy it into another character array b, from the 4th position (meter).For this purpose we write strncpy (a,b,4). Hence it need 3 arguments. And in this way it is different than strcpy.

d) strcat function is used to concatinate two strings. Hence when we use strcat there should be proper memory spaces available after the first string.For example, suppose a character array a contains the string "american" and character array b contains the string"house" and we perform strcat(a,b). Then the output that we get in a is "americanhouse"

e) In the given program the compiler gives the error due to strcat funtion because,as explaines earlier,the first string must contain proper number of spaces to get cocatinated with the second string. Here we dont have the scope of managibg those spaces for second string to join.

if any doubt you can seek further clarifications.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote