+ 2
How do I find the number of âsâ character in the code
3 RĂ©ponses
+ 8
while(str[i] =='s');
Its the same of saying "iterate the string until you find first s"
You need to put a condition inside while to iterate all the string and using a if test (str[i] =='s');
edit here :
https://code.sololearn.com/cd9KJWofJs3q/?ref=app
+ 4
I'd use this:
int count = 0;
char s[] = "So this is our little test string.";
for (int i=0; s[i]!='\0' ; ++i)
if (s[i] == 's' || s[i] == 'S')
++count;
printf("%d", count);
+ 1
thanks for the help Anya , i also tried
int main()
{
int count = 0;
int i;
char str [30]="Saturday afternoon is sunny\0";
for (i=0; str[i] != '\0';i++)
//for (i= 0; str[i]== 's';i++)
//while (str=='s'|| str == 'S');
if (str[i] == 's' || str[i] == 'S')
count++ ;
printf("Number of s characters in the string is %d\n", count); //output: 3
return 0;
}