I have written the program as in the example of week 2, I can not find anything I have done differently, unfortunately. I have not declared the counting variable i and n, as in the example, however, in my case there is a warning about this and undeclared identifiers.

I can't debug as it is not a compiled program, is there any other method of checking and going through a program to find the source of the problem, if I am not able to use the debugger as in this case, just to clarify I can't use the debug50 debug function as it is giving me this warning: Can't debug this program! Afraid debug50 only supports compiled C programs! enter image description here

  • 1
    Please add the source code as text as I am not able to access the image, and it will be easier to help you that way. – akshayk.vnit Jul 24 '17 at 12:09

Use a comma, not semicolon, between int i = 0 and n = strlen(s). Otherwise, you'd have three semicola within the for loop's head, where only exactly two are allowed.

You might not want to return 0; within the loop.

[edit] As @Securiter added, a for loop's head has three parts, all three being expressions (so no semicolon inside allowed):

for (initialisation; loop_condition; step)

All three parts are optional, the semicola are not.

  1. In the initialisation part, you can declare multiple variables of the same type using like int a = 47, b = 11, answer = 42. You don't have to initialise all variables you declare, and you cannot declare variables of different types.

  2. The condition, which is checked before entering the body, should result in non-zero (so not false or NULL or 0) if you mean to continue the loop. If the condition is missing, it's assumed to always be true, and you would use other means to leave the loop (like break;, return, or ending the programme).

  3. The third expression, executed after leaving the body (and before checking the condition for the next iteration), is usually used to advance an index or pointer, like node = node->next or index += step.

  • To add to Blauelf, in FOR loops, you can declare multiple variables at the beginning, more than 1 or 2 but they are always separated by a comma not a semicolon, the semicolon is a tool for separating between the 3 stages of the FOR loop: intialisation, condition and afterthought. (you'll need to understand this further in the course, @DerTraumwanderer). – Securiter Jul 24 '17 at 12:21
  • Yes the comma was the problem indeed, I was sure I checked everything and it looked identical, very important lesson to me and proves to me how important it is also to get a second opinion. Thank you for the feedback. – Der Traumwanderer Jul 24 '17 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .