0
0
Cprogramming~10 mins

String handling using library functions - 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 using a standard library function.

C
#include <string.h>
#include <stdio.h>

int main() {
    char source[] = "Hello";
    char destination[10];
    [1](destination, source);
    printf("%s", destination);
    return 0;
}
Drag options to blanks, or click blank then click option'
Astrcpy
Bstrlen
Cstrcmp
Dstrcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcmp instead of strcpy, which compares strings but does not copy.
Using strlen which returns length, not copying.
Using strcat which concatenates strings instead of copying.
2fill in blank
medium

Complete the code to find the length of the string using a standard library function.

C
#include <string.h>
#include <stdio.h>

int main() {
    char str[] = "Hello, world!";
    int length = [1](str);
    printf("Length: %d", length);
    return 0;
}
Drag options to blanks, or click blank then click option'
Astrlen
Bstrcpy
Cstrcmp
Dstrcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy which copies strings, not length.
Using strcmp which compares strings, not length.
Using strcat which concatenates strings, not length.
3fill in blank
hard

Fix the error in the code to compare two strings correctly using a standard library function.

C
#include <string.h>
#include <stdio.h>

int main() {
    char str1[] = "apple";
    char str2[] = "apple";
    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'
Astrcpy
Bstrcmp
Cstrlen
Dstrcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy which copies strings, not compares.
Using strlen which returns length, not compares.
Using strcat which concatenates strings, not compares.
4fill in blank
hard

Fill both blanks to concatenate two strings safely using a standard library function.

C
#include <string.h>
#include <stdio.h>

int main() {
    char str1[20] = "Hello, ";
    char str2[] = "World!";
    [1](str1, str2, [2]);
    printf("%s", str1);
    return 0;
}
Drag options to blanks, or click blank then click option'
Astrncat
Bstrcpy
Csizeof(str1) - strlen(str1) - 1
Dstrlen(str2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using strcpy which overwrites instead of appending.
Using strlen(str2) which may cause overflow if str1 is small.
Not calculating buffer size correctly.
5fill in blank
hard

Fill all three blanks to create a substring by copying part of a string using standard library functions.

C
#include <string.h>
#include <stdio.h>

int main() {
    char source[] = "Programming";
    char substring[10];
    strncpy(substring, source + [1], [2]);
    substring[[3]] = '\0';
    printf("%s", substring);
    return 0;
}
Drag options to blanks, or click blank then click option'
A3
B6
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Not adding the null terminator, causing garbage output.
Copying wrong number of characters.
Starting from wrong index.