Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int str_chnum(const char str[], char c) {
- int count = 0;
- int i;
- for (i = 0; str[i] != '\0'; i++)
- if (str[i] == c) count++;
- return count;
- }
- int main(void) {
- char str[128];
- char ch;
- printf("文字列を入力してください:");
- scanf("%127[^\n]%*[^\n]", str);
- getchar(); // skip "\n"
- printf("検索する文字を入力してください:");
- scanf("%c%*c", &ch);
- printf("%cは%d個ありました。\n", ch, str_chnum(str, ch));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement