Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to copy the string from source to destination.
C
#include <string.h> #include <stdio.h> int main() { char source[] = "Hello"; char destination[10]; [1](destination, source); printf("%s\n", destination); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strlen instead of strcpy will cause errors because strlen returns length, not copy.
Using strcmp compares strings but does not copy.
Using strcat appends strings instead of copying.
✗ Incorrect
The function strcpy copies the content of the source string into the destination string.
2fill in blank
mediumComplete the code to find the length of the string text.
C
#include <string.h> #include <stdio.h> int main() { char text[] = "Programming"; int length = [1](text); printf("Length: %d\n", length); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy will copy strings but not give length.
Using strcmp compares strings but does not give length.
Using strcat concatenates strings but does not give length.
✗ Incorrect
The function strlen returns the number of characters in the string, excluding the null terminator.
3fill in blank
hardFix the error in the code to compare two strings str1 and str2.
C
#include <string.h> #include <stdio.h> int main() { char str1[] = "apple"; char str2[] = "orange"; if ([1](str1, str2) == 0) { printf("Strings are equal\n"); } else { printf("Strings are different\n"); } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy copies strings but does not compare.
Using strlen returns length, not comparison result.
Using strcat concatenates strings, not compares.
✗ Incorrect
The function strcmp compares two strings and returns 0 if they are equal.
4fill in blank
hardFill both blanks to concatenate suffix to base and print the result.
C
#include <string.h> #include <stdio.h> int main() { char base[20] = "file"; char suffix[] = ".txt"; [1](base, suffix); printf("%s\n", [2]); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy instead of strcat will overwrite base.
Printing suffix instead of base will not show the combined string.
✗ Incorrect
strcat appends suffix to base. Then printing base shows the combined string.
5fill in blank
hardFill all three blanks to create a new string result that contains the uppercase version of word and print its length.
C
#include <stdio.h> #include <string.h> #include <ctype.h> int main() { char word[] = "hello"; char result[10]; for (int i = 0; i < strlen(word); i++) { result[i] = [1](word[i]); } result[strlen(word)] = '\0'; printf("%s\n", [2]); printf("Length: %d\n", [3](result)); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using tolower will convert letters to lowercase, not uppercase.
Printing word instead of result will show the original string.
Using strlen on word instead of result will not reflect changes.
✗ Incorrect
toupper converts each character to uppercase. We print the result string and then its length using strlen.