Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // apple xcode
- // paulogp
- /* ocorrencia: numero de vezes que um caracter aparece numa palavra */
- #include <stdio.h>
- #include <string.h>
- int ocorrencia (char *the_input, char the_char);
- int ocorrencia (char *the_input, char the_char)
- {
- int i = 0;
- int the_counter = 0;
- for (i = the_counter = 0; the_input[i] != '\0'; i++)
- {
- if (the_input[i] == the_char)
- {
- the_counter++;
- }
- }
- return the_counter;
- }
- int main (int argc, const char * argv[])
- {
- char the_input[21]; // max 20 digits + '\0'
- char the_char[2]; // char to search + '\0'
- int the_result;
- printf ("palavra: ");
- fgets (the_input, sizeof(the_input) + 1, stdin);
- printf ("letra: ");
- fgets (the_char, sizeof(the_char), stdin);
- the_result = ocorrencia (the_input, the_char[0]);
- printf ("%c aparece %i vezes\n", the_char[0], the_result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement