stevenhalim / cpbook-code

CP4 Free Source Code Project (C++17, Java11, Python3 and OCaml)
2k stars 493 forks source link

Fix string comparison to include newline. #76

Open aldian opened 3 years ago

aldian commented 3 years ago

My Linux system won't allow me to use gets function as probably it is not safe, so I have to use fgets:

 error: ‘gets’ was not declared in this scope
       scanf("%d ", &d); gets(line); 
                         ^~~~

So using fgets is good for compatibility. However, fgets includes newline to the result, so without this simple fix, the code will loop forever as 4 strcmps at line 49-55 won't match.

Jakester78 commented 1 year ago

Merge pls