Given a string and a character, I have to find how many times the character exists in the string.
This is what I have so far:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main ()
{
char string[10];
char c1, c2;
int contador, i, l, n;
printf ("Introduza uma string e dois caracteres.\n");
scanf ("%s %c %c", &string[i], &c1, &c2);
l = strlen (string);
contador = 0;
for (n = 0; n < l; n++)
{
if (c1 == string[i])
{
contador = contador + 1;
}
}
printf ("%d\n", contador);
}
The text in printf is in portuguese, and it means "Introduce a string and two characters". The second character is there for later.
Would appreciate any help you can give.