+ 2

Whats wrong in this?

string length without using strlen https://code.sololearn.com/cjqQQ4RhSSzW/?ref=app want to output the total no.of characters like 5 not like 0,1,2,3,4,

28th Oct 2018, 6:42 PM
Abhay
Abhay - avatar
7 odpowiedzi
+ 4
Line 8 and 9: for(i = 0; s[i] !='\0'; ++i); printf(" %s\nLength of string: %d",s, i);
28th Oct 2018, 7:05 PM
Ipang
+ 2
it still doesn't gives the answer 5?
28th Oct 2018, 9:23 PM
Abhay
Abhay - avatar
+ 2
or I say it gives same answer just the name of sting ,which I didn't needed anyway
28th Oct 2018, 11:07 PM
Abhay
Abhay - avatar
+ 2
Abhay, note the semicolon at the end of line 8, the for loop should terminate on that very line, otherwise, line 9 will be considered as loop body; if we don't have the semicolon at end of line 8.
29th Oct 2018, 3:29 AM
Ipang
+ 2
woo thks 😄and all time I thought we don't terminate for Loop with semicolon!!
30th Oct 2018, 9:06 PM
Abhay
Abhay - avatar
+ 2
You're welcome Abhay. Also when we put semicolon at end of a loop it means we're creating a loop without a body, but the values in the loop initialization will still change, difference is just the loop doesn't have loop body : )
31st Oct 2018, 4:46 AM
Ipang
+ 2
thks for the valuable info,
31st Oct 2018, 4:27 PM
Abhay
Abhay - avatar