C语言应该是基础题!刚学C语言的,讲解!

原文:
Task 15
Read a string using "%s" in a scanf statement and count the number of character 'a' in that string. Assume that the total number of characters in the string will not exceed 49 and the string has no spaces.
Requirements:
No string functions (e.g., strlen) are allowed.
For example, if the input is ab#icda1e a
then the output will be 3.

译文:
任务15
在scanf语句中使用"%s"读取字符串,并计算该字符串中字符'a'的数量。假设字符串的总字符数不超过49个,且字符串中没有空格。
要求:
不允许使用字符串函数(例如strlen)。
例如,如果输入是ab#icda1ea
那么输出就是3。

    char s[50];
    int num = 0;
    scanf("%s", &s);
    for (int i = 0; s[i] != '\0'; i++)
        if (s[i] == 'a')
            num++;
    printf("%d ", num);