New course! Every coder should learn Generative AI!
Try a free lesson+ 4
Avengers please take help from my brother HARDIK JAIN HARSORA [Akshat] 👍👍
+ 3
Avengers if something like this is entered "___###_#_#_#___#", then at position 0 , we have '_' , so here loop will never run , also that 0 isn't confirmed as you haven't initialized it with a value, it could be some garbage value as well.
and what is charwithspace and charwithoutspace ?? is this program suppose to check for spaces or hashes(#) ??
+ 3
Avengers if '_' denotes for empty space then you should check for '_' instead of ' ' , right ?
+ 3
Avengers and remove that "if str[i]==35" which isn't really helping at all and stopping program execution if starting character isn't "#"
+ 2
The question statment you specified here is different from the one that exist in your code.
What exactly is the question here ?
As of why you code is not displaying anything right now for the test input you provided, then (as already specified by Abhay )it is because the value of *i* in unitialised at line 13 " if(str[i] == 35) " ( leading to undefined behaviour )
If you are looking a way to count number of characters with and without spaces seperately
Then why don't you just traverse the input string once and keep track of both counts accordingly.
Sometimes like this :
for(i=0; str[i]!='\0'; i++)
{
countWithSpace++;
if(str[i] != '_')
countWithoutSpace++;
}
+ 1
Avengers why " if(str[i]==35) " ?,
Why are you checking if character at position 0 is "#" or not
0
Thank you so much
- 1
I want someone to help me make this application
- 1
l want to learn every thing about C++ from zero to the end