0
0
Cprogramming~10 mins

Common string operations - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Astrcpy
Bstrlen
Cstrcmp
Dstrcat
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.
2fill in blank
medium

Complete 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'
Astrcpy
Bstrcat
Cstrcmp
Dstrlen
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.
3fill in blank
hard

Fix 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'
Astrlen
Bstrcmp
Cstrcpy
Dstrcat
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.
4fill in blank
hard

Fill 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'
Astrcat
Bstrcpy
Cbase
Dsuffix
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.
5fill in blank
hard

Fill 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'
Atoupper
Bresult
Cstrlen
Dtolower
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.