Jump to content
1 minute ago, M.Yurizaki said:

What's your development environment?

I'm working with Microsoft Visual Studio 2008 on win32 console app

CPU: Intel Core i9-10900K  MOBO: ROG MAXIMUS XII FORMULA GPU: 2080ti Hall of Fame 10th anniversary limited edition  PSU: Asus ROG THOR 1200W  COOLER: Optimus foundation black acetal RADS: 3x EKWB CoolStream PE 360  LOOP: EKWB torque HDC fittings / EKWB ZMT 15,9/9,5mm / EKWB CryoFuel Clear MONITOR: Acer predator X34

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9360893
Share on other sites

Link to post
Share on other sites

1 minute ago, TheRedViper said:

I'm working with Microsoft Visual Studio 2008 on win32 console app

Are you using the debugger, setting a break point at the scanf, and stepping through to see what's going on?

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9360904
Share on other sites

Link to post
Share on other sites

1 minute ago, M.Yurizaki said:

Are you using the debugger, setting a break point at the scanf, and stepping through to see what's going on?

no

CPU: Intel Core i9-10900K  MOBO: ROG MAXIMUS XII FORMULA GPU: 2080ti Hall of Fame 10th anniversary limited edition  PSU: Asus ROG THOR 1200W  COOLER: Optimus foundation black acetal RADS: 3x EKWB CoolStream PE 360  LOOP: EKWB torque HDC fittings / EKWB ZMT 15,9/9,5mm / EKWB CryoFuel Clear MONITOR: Acer predator X34

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9360907
Share on other sites

Link to post
Share on other sites

1 minute ago, M.Yurizaki said:

You should really familiarize yourself with the debugger and how to work it. This will save you an astronomical amount of headaches.

I think my teacher wants us to have headaches, but like I said il ask him tomorrow because I cant advance right now.

CPU: Intel Core i9-10900K  MOBO: ROG MAXIMUS XII FORMULA GPU: 2080ti Hall of Fame 10th anniversary limited edition  PSU: Asus ROG THOR 1200W  COOLER: Optimus foundation black acetal RADS: 3x EKWB CoolStream PE 360  LOOP: EKWB torque HDC fittings / EKWB ZMT 15,9/9,5mm / EKWB CryoFuel Clear MONITOR: Acer predator X34

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9360931
Share on other sites

Link to post
Share on other sites

11 hours ago, TheRedViper said:

yeah

That really should not be possible. It is possible for your program to get stuck in an infinite loop because you do not check scanf's return value in both calls. If scanf encounters a character that does not match the required format, it will not consume the character and indicate trough its return value that it failed to read some of the requested items. Because the character that caused the read to fail stays stuck in stdin, scanf will keep failing and get your program in a infinite loop.

 

However, even if that happens all the printf's in between should still happen. Merely repeating that 1 line is impossible with the code you've shown.

 

The REAL solution is to stop using scanf, it's been considered a unsafe function for decades now, and newer versions of MSVC++ and GCC even complain about it being deprecated. The canonical solution is to use fgets to safely read lines that are guaranteed not to overflow your input buffer and then parse the line.

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9362907
Share on other sites

Link to post
Share on other sites

20 hours ago, M.Yurizaki said:

You should really familiarize yourself with the debugger and how to work it. This will save you an astronomical amount of headaches.

 

8 hours ago, Unimportant said:

That really should not be possible. It is possible for your program to get stuck in an infinite loop because you do not check scanf's return value in both calls. If scanf encounters a character that does not match the required format, it will not consume the character and indicate trough its return value that it failed to read some of the requested items. Because the character that caused the read to fail stays stuck in stdin, scanf will keep failing and get your program in a infinite loop.

 

However, even if that happens all the printf's in between should still happen. Merely repeating that 1 line is impossible with the code you've shown.

 

The REAL solution is to stop using scanf, it's been considered a unsafe function for decades now, and newer versions of MSVC++ and GCC even complain about it being deprecated. The canonical solution is to use fgets to safely read lines that are guaranteed not to overflow your input buffer and then parse the line.

 

The problem turned out to be microsoft studio. The code was running fine. Thank you for helping though, it is greatly appreciated!

CPU: Intel Core i9-10900K  MOBO: ROG MAXIMUS XII FORMULA GPU: 2080ti Hall of Fame 10th anniversary limited edition  PSU: Asus ROG THOR 1200W  COOLER: Optimus foundation black acetal RADS: 3x EKWB CoolStream PE 360  LOOP: EKWB torque HDC fittings / EKWB ZMT 15,9/9,5mm / EKWB CryoFuel Clear MONITOR: Acer predator X34

Link to comment
https://linustechtips.com/topic/736265-c-coding-help/page/2/#findComment-9364976
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×