ConceptStep · learning platform for computer science

String processing: vowels and search

C programming · Lesson

C · lesson 24 / 27

String processing: vowels and search

Scan a string once and observe how the same traversal can update multiple results: vowel count and the position of the first searched character.

1 · Observe and predict

The concept

During one traversal you can evaluate conditions on the current character and update accumulators or search results. In this example vocali counts A/E/I/O/U and posizione stores the first index of A.

Mental model:

i=0 → while parola[i] != '\0' → vowel? update count → first A? save i → i++

2 · Flowchart + String Memory

Follow the same algorithm as a flowchart

The flowchart shows the logical string value; the String Memory Explorer below shows the individual char cells and the \0 terminator actually required in C.

Loading flowchart…
3 · String Memory Explorer

See the string as memory cells

Each cell contains one char. The \0 terminator occupies a real cell and tells C functions where the string ends.

1 / 7

Start · i=0 · vowels=0 · position=-1

The string is ready. We search for A and use the same traversal to count vowels.

4 · Flowchart ↔ C · Run in Page

Lab 1 — Run the example program

Run C executes only the example shown on the left, using stdin on the right. The coding challenge below has a separate editor and test button.

String processing Start the flowchart to synchronize the code
                        1#include <stdio.h>
                        2 
                        3int main(void)
                        4{
                        5    char parola[] = "CIAO";
                        6    char cercato = 'A';
                        7    int vocali = 0;
                        8    int posizione = -1;
                        9    int i = 0;
                        10 
                        11    while (parola[i] != '\0')
                        12    {
                        13        int e_vocale =
                        14            parola[i] == 'A' || parola[i] == 'E' ||
                        15            parola[i] == 'I' || parola[i] == 'O' ||
                        16            parola[i] == 'U';
                        17 
                        18        if (e_vocale)
                        19            vocali = vocali + 1;
                        20 
                        21        if (posizione == -1 && parola[i] == cercato)
                        22            posizione = i;
                        23 
                        24        i = i + 1;
                        25    }
                        26 
                        27    printf("%d\n", vocali);
                        28    printf("%d\n", posizione);
                        29    return 0;
                        30}
Ready. Make a prediction before running.

                    
                

Lab 2 — Coding challenge: write your code — Count vowels

Read an uppercase word and count vowels A E I O U.

This is a different program from lab 1. Complete the starter code: Check all test cases compiles this editor and tests every input, including boundary cases.

5 · Guided practice

Check your prediction

With parola = "CIAO" and searched character = 'A', what results do you get?

Challenge 1 / 5 · Understanding

Progress: 0 / 5 · correct: 0

Your competency map

What you need to know for String processing: vowels and search

ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.

Current topic Strong skill Review due Needs reinforcement To be mastered Optional support

Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.

GUIDED LEARNING PATHS

Want to choose the next skill to develop?