Jump to content
  • 0

infinite loop on SDK with scanf (retired ZYBO)


enriqeat

Question

Hi, I get infinite loops when I enter a digit which is not expected from scanf function while programming a standalone application for the retired version of zybo. what I want is to enter just an integer. I used the next code to avoid entering something that is not an integer by accident, as an alternative for scanf. This works great on CodeBlocks, but when I try to use it on SDK it does not work, it's like I cannot enter anything. How can I solve this issue? should I use another function or library?

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   
    char *p, s[100];
    int n;
while(1)
{


    while (fgets(s, sizeof(s), stdin)) {
        n = strtol(s, &p, 10);
        if (p == s || *p != '\n') {
            printf("Please enter an integer: ");
        } else break;
         printf("You entered: %d\n", n);
    }
  printf("the number is %d\n",n);

}
}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Hi @enriqeat,

1) can you be more specific on where are you trying to read data from.  I.E. usb uart bridge, BRAM, Ethernet,  DDR3.

I would guess you are trying to read data entered into a serial terminal from a PC using the usb uart  bridge. Here is a  xilinx thread that discusses using the usb uart bridge. You should also be able to find an example as discussed in this thread.

thank you,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...