Output is wrong for counting number of words

Output is wrong for counting number of words question. I’m trying this question https://hack.codingblocks.com/contests/c/537/901 and my solution is this https://ide.codingblocks.com/s/38637.
Please tell me what is the mistake in the code

Hey Simran, you are iterating in array n till 99th index, but it is possible that if you get the string of length 10 then the indexes from 11 to 99 may contain garbage value. So to correct this error, update your for loop as
for(int i=0; n[i]!=’\0’; i++){
}

1 Like