Weird fgets and gets behavior

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Weird fgets and gets behavior

Postby fly135 » Wed Sep 12, 2018 2:45 pm

Was trying to use fgets or gets for user input. The functions don't wait for a newline. They seem to time out in about a sec and return whatever characters were typed.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Weird fgets and gets behavior

Postby fly135 » Wed Sep 12, 2018 3:00 pm

Looks like you have to implement your own version of the function using getchar. Which is non blocking as well and will return immediately. So you need to put a sleep/delay in whenever you don't get a char.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Weird fgets and gets behavior

Postby ESP_igrr » Wed Sep 12, 2018 3:05 pm

By default, reading from stdin is non-blocking. If you install the UART driver, you should be able to do blocking reads. Please see examples/system/console for an example of how to enable blocking reads from stdin. Also please see https://docs.espressif.com/projects/esp ... out-stderr

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Weird fgets and gets behavior

Postby fly135 » Wed Sep 12, 2018 4:33 pm

Oh cool! Thanks for the info.

John A

Who is online

Users browsing this forum: No registered users and 114 guests