c - If and equality statements -


I am trying to solve this problem but I do not know why my code is not working. Any help is appreciated Edit: The edit below has been edited to edit, but the second line of output still has an additional "15" (in bold) and I do not know where it comes from Used to be.

My Output

18662658515 5552272 15

#include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; Int main (zero) {int n; Int j; Scanf ("% d \ n", & amp; n); Int i = 0; Four oysters [15]; For the (fgets (mystr, 15, stdin); (J = 0; J & lt; 15; J ++) for {

The problem is that you are repeating all 15 letters in this input String, regardless of the length of the input. The first test case has 11 characters, but in the second case only 8 is. In the second instance, you are accidentally processing the last two letters from the input before the error, which is 15 .

To fix this, when you press NUL character 0, stop it running, which ends the string by changing this line

 for  (J = 0; j & lt; 15; j ++) { 

to

  (j = 0; mystr [j]! = 0; j ++) { 

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -