小编Bos*_*evz的帖子

查找数字5出现在0 - 4322之间的次数

这段代码似乎对我不起作用.它输出的数字17显然是错误的.如果遇到5,15,25,50等数字,计数器应该会上升.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(void) {
    int i;
    int counter; 
    char num[4322];

    for (i = 1; i < sizeof(num); i++){
        num[i] = i;
        if ( strstr(&num[i], "5")){
            counter = counter + 1;
        }
    } 

    printf("%d", counter);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c arrays string pointers strstr

0
推荐指数
1
解决办法
50
查看次数

标签 统计

arrays ×1

c ×1

pointers ×1

string ×1

strstr ×1