I'm trying to use fgets to read from a terminal on stdin. Rather than waiting for a return, a full buffer or an EOF it always returns NULL.
When I type a characters in it gets it - sometimes more than one character. Is there a timeout somewhere that I'm not aware of?
Code looks like this n(i.e. it always returns NO_INPUT)
int getLine (char *prmpt, char *buff, size_t sz) {
int ch, extra;
// Get line with buffer overrun protection.
if (prmpt != NULL)
{
printf ("%s", prmpt);
fflush (stdout);
}
if (fgets (buff, sz,stdin) == NULL)
{
return NO_INPUT;
}
if (buff[strlen(buff)-1] != '\n') {
extra = 0;
while (((ch = getchar()) != '\n') && (ch != EOF))
extra = 1;
return (extra == 1) ? TOO_LONG : OK;
}
buff[strlen(buff)-1] = '\0';
return OK;
}
fgets always returns NULL on stdin
Re: fgets always returns NULL on stdin
reads from stdin currently behave as O_NONBLOCK, which is mentioned here:
http://esp-idf.readthedocs.io/en/latest ... out-stderr
The function which reads from the UART gets all the characters present in the FIFO and returns. Blocking reads support is something which needs to be implemented.
http://esp-idf.readthedocs.io/en/latest ... out-stderr
The function which reads from the UART gets all the characters present in the FIFO and returns. Blocking reads support is something which needs to be implemented.
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 72 guests