Bird
0
0
DSA Cprogramming~10 mins

String Traversal and Character Access in DSA C - Interactive Practice

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

Complete the code to print each character of the string using a loop.

DSA C
char str[] = "hello";
for (int i = 0; i < [1]; i++) {
    printf("%c\n", str[i]);
}
Drag options to blanks, or click blank then click option'
Astr.length
B5
Cstrlen(str)
Dsizeof(str)
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(str) which includes the null terminator and size of array.
Using a fixed number without considering string length.
2fill in blank
medium

Complete the code to access the last character of the string.

DSA C
char str[] = "world";
char last_char = str[[1]];
printf("%c\n", last_char);
Drag options to blanks, or click blank then click option'
Astrlen(str) - 1
Bsizeof(str) - 1
Cstrlen(str)
Dsizeof(str)
Attempts:
3 left
💡 Hint
Common Mistakes
Using strlen(str) as index which is out of bounds.
Using sizeof(str) which includes null terminator.
3fill in blank
hard

Fix the error in the code to correctly print characters until the null terminator.

DSA C
char str[] = "test";
int i = 0;
while (str[[1]] != '\0') {
    printf("%c\n", str[i]);
    i++;
}
Drag options to blanks, or click blank then click option'
Astrlen(str)
B0
C1
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed index like 0 or 1 in the condition causes infinite loop or wrong output.
Using strlen(str) inside the condition without updating index.
4fill in blank
hard

Fill both blanks to create a loop that prints characters only if they are vowels.

DSA C
char str[] = "example";
for (int i = 0; i < [1]; i++) {
    if (str[i] == [2]) {
        printf("%c\n", str[i]);
    }
}
Drag options to blanks, or click blank then click option'
Astrlen(str)
B'a'
C'e'
D'x'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop limit causing out of bounds.
Checking for a consonant instead of a vowel.
5fill in blank
hard

Fill all three blanks to create a loop that counts how many times 'l' appears in the string.

DSA C
char str[] = "hello world";
int count = 0;
for (int i = 0; i < [1]; i++) {
    if (str[i] == [2]) {
        [3];
    }
}
printf("%d\n", count);
Drag options to blanks, or click blank then click option'
Astrlen(str)
B'l'
Ccount++
Di++
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong character in condition.
Not incrementing count inside if block.