Display issue when we print in for loop

Hi All,

I have connected to the board using telnet, when i tried to display huge record which has more then 1000, this telnet session where overlapping the printed data to the previous line.

Can some one help me how to solve this?

For example"

in a for loop i am printing
"1 Name1"
"2 Name2"
"3 Name3"

suddenly when i check the output its get overlapped like

"1 Name 1"
"2 N Name3"
"4 Name4"

Its not happening all the time, I know its not happening because of the code. Do we need to anything on the telnet screen to avoid this. I am running this in Linux OS

There's nothing magical about telnet which will cause it to interleave data of its own accord, no. Your code really is printing them out of order. Perhaps a command running in the background didn't execute precisely in the order you intended? Or the very long data is getting accidentally truncated somewhere.

I suspect the problem really is your code, your data, or the way you're running the command. Not having been told what any of these are, I can't guess any further than that. Please show what you're doing.

I am just using the following api to print the message

disp_db_entry (dev_db *ptr)
{
    char buff[128];

    memset(buff, 0, 128);

    if (ptr->dev_type == DEVICE_NUMBER) {
        snprintf(buff, sizeof(buff), "Dev Number :");
    snprintf(buff + strlen(buff), sizeof(buff), "%8x", ptr->num);
    } else if (ptr->dev_type == DEVICE_NAME){
        snprintf(buff, sizeof(buff), "dev Name :");
        snprintf(buff + strlen(buff), sizeof(buff), "%s", ptr->name);
    } else if (ptr->dev_type == DEVICE_MODEL){
        snprintf(buff, sizeof(buff), "Model Number :");
        snprintf(buff + strlen(buff), sizeof(buff), " %8x", ptr->model);
    }

    snprintf(buff + strlen(buff), sizeof(buff), "- Type %d", ptr->dev_type);

    printf("%s\n", buff);
    
}

The output that would produce doesn't resemble the output you showed at all. What does the output actually look like?

What program's using that function is just as important as what's in the function, too. If there's more than one thread or more than one process going they'll need to be controlled somehow so they don't print overtop each other.