+ 2
Why it is not counting the string c
Its not working https://code.sololearn.com/c4FoM86qY7o3/?ref=app
2 odpowiedzi
+ 5
there is a mistake in the countLength function.
The for loop condition i != '\0' is incorrect because i is an integer index, not a character. Instead, the loop condition should check if the current character in the string is not equal to '\0', which represents the end of the string. The correct condition is arr[i] != '\0'.
Additionally, the if statement inside the loop checks if i is equal to 'c', which is a character literal, instead of checking if the current character in the string is equal to 'c'. The correct condition is arr[i] == 'c'.
int countLength(char arr[])
{
int count = 0;
for (int i = 0; arr[i] != '\0'; i++)
{
if (arr[i] == 'c')
{
count++;
}
}
return count;
}
+ 1
Thanks 👍 it worked