Find the error in each of the following program segments and explain how to corr
ID: 3806212 • Letter: F
Question
Find the error in each of the following program segments and explain how to correct it: a) char s [10]; strncpy (s, "hello", 5); b) printf ("%s", 'a'); c) char s[12]; strcpy (s, "Welcome Home"); d) if (strcmp (string1, string2)) {printf ("The strings are equal ");} Write code to accomplish each of the following: a) Define a structure called part containing int variable partNumber and char array partName with values that may be as long as 25 characters (including the terminating null character). b) Declare variable a to be of type struct part, array b[10] to be type struct part. c) Read a part number and a part name from the keyboard into the individual members of variable a, which declared in b). (Note that partName is a char array with 25 elements.)Explanation / Answer
HI, I have answered Q1 completely
Please repost other questions.
Please let me know in case of any issue in Q1.
Q1)
a)
After copy: strncpy(s, "hello", 5),
we are not ending 's' with '' character
Correct:
strncpy(s, "hello", 5);
s[5] = '';
b)
Error: %s specifier for character
Correct:
printf("%c", 'a');
c)
length of "Welcome Home" = 12
Error: we need one more space to mark end of string in 'c'
Correct:
char s[13];
d)
No error
the obly thing is that string1 and string2 should be defined and valid string
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.