You need to intialize variables a
and b
.
I think like this
char a="a", b='b';
Check this code. I think this is what you need
int main ()
{
char string[20];
char a="a", b='b';
int i = 0;
int sum = 0;
printf (" my word is:\n");
scanf ( "%s", string);
for (i = 0; string[i] !='\0'; i++)
{
if (string[i]==a )
{
sum= sum + 1;
}
else if (string[i]==b )
{
sum= sum + 2;
}
}
printf ("%d\n" , sum);
return 0;
}
12
solved Comparing characters of a string [closed]