hey here i am trying to return 0 if argument string contains all 26 alphabet characters otherwise function should return 1 and print message]1 ]
1 Answer
Your loop will never end normally (after 26 iterations). This is because in the first iteration of the loop, your function will always execute one of the two return
statements. This means that the first iteration of the loop will never finish normally.
However, the compiler is not smart enough to know that the loop will never end normally. It only sees that if the loop ends normally after 26 iterations, there is no return
statement after the loop, although you defined the function in such a way that it returns a value of type int
. That is why the compiler is complaining.
In order to satisfy the compiler, you could simply add some kind of return
statement after the loop. However, this would not fix the underlying problem.
The underlying problem is that the first iteration of your loop will never end normally. This means that the logic of your program is incorrect.
You wrote your program in such a way that it will abort the first iteration of the loop with return 1;
if it detects that the first character of s
is not an alphabetic character. This is correct. However, you also wrote your program in such a way that it will abort the first iteration of the loop with return 0;
if it detects that the first character is an alphabetical character. This does not make sense. You also want to check the other 25 characters whether they are also alphabetic, before you execute return 0;
. Therefore, you should put the return 0;
after the loop and remove the else
statement. This would also solve the issue of the compiler complaining that there is no return
statement after the loop.