Professional Documents
Culture Documents
CS1200 Spring 2018 Assignment 5
CS1200 Spring 2018 Assignment 5
Assignment 5
Total number of questions: 3
Total points: 30
Submission Guideline: Write your answer in a word document and submit to e-learning.
(10pts) Q1. Find the error in each of the following program segments and explain how to
correct it:
a) char s[10];
strncpy(s, “hello”, 5);
printf(“%s\n”, s);
b) printf(“%s”, ‘a’);
c) char s[12];
strcpy(s, “Welcome Home”);
d) if (strcmp(string1, string2)) {
printf(“The strings are equal\n”);
}
(10pts) Q2. What does this program do? And explain your answer.
#include <stdio.h>
int main(void)
{
char string1[80], string2[80]; /* create char array */
printf ("Enter two strings : ");
scanf ("%s%s", string1, string2);
mystery1 (string1, string2);
printf ("%s\n", string1);
return 0; /* indicates successful termination */
}
int main(void)
{
char string[80]; /* create char array */
printf ("Enter a string: ");
scanf ("%s", string);
printf ("%d\n", mystery2 (string));
return 0; /* indicates successful termination */
}