• 0

infinite loop on SDK with scanf (retired ZYBO)


Posted (edited)

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 (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);


Edited by enriqeat

Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

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,


Share this post

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