0
need help with this question
Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n Nobody the output is: 0 Your program must define and call the following function that returns the number of times the input character appears in the input string. int CountCharacters(char userChar, char* userString)
5 Answers
0
this is what i have down so far
#include <stdio.h>
#include <string.h>
int main() {
char ch;
char str[50];
int count = 0, i;
scanf(" %c", &ch);
scanf("%s", str);
for (i = 0; i < strlen(str); ++i) {
if (str[i] == ch) {
++count;
}
}
printf("%d\n", count);
return 0;
}
0
https://imgur.com/Y2Jvp45 for some reason im getting error messages which I don't understand
0
so where exactly would implement those in my query
0
should i remove;
scanf(" %c", &ch);
scanf("%s", str);
and put;
scanf("%49[^\n]%*c", str);
0
so that means i have to rework my entire query