0

I am trying to find the string length using for loop but there is some error

#include <iostream> #include<string> #include<cstring> using namespace std; void harsh(){ char text[100]; cin>>text; int a=0; int i=0; for( i=0;text[i]!='\0';i++) { a++; cout<<"\nstring length is"<<a; } } int main() { harsh(); return 0; } Output: String length is 1 String length is 2 String length is 3 String length is 4 String length is 5 Input: There Why this is happening Help me!! https://code.sololearn.com/cp75TPia7YMB/?ref=app https://code.sololearn.com/cp75TPia7YMB/?ref=app

25th Jul 2020, 5:21 PM
Harsh Sharma
Harsh Sharma - avatar
5 Answers
+ 2
Thank you so much it works
25th Jul 2020, 5:32 PM
Harsh Sharma
Harsh Sharma - avatar
+ 2
Thank you
25th Jul 2020, 5:38 PM
Harsh Sharma
Harsh Sharma - avatar
+ 2
Thank you now my concept is clear
25th Jul 2020, 5:50 PM
Harsh Sharma
Harsh Sharma - avatar
+ 2
Thank you i will use this in my projects
25th Jul 2020, 5:56 PM
Harsh Sharma
Harsh Sharma - avatar
+ 1
Yes i noticed that but why you don't use curly braces
25th Jul 2020, 5:41 PM
Harsh Sharma
Harsh Sharma - avatar