Visualization of bubble sort in progress I've written a program showing the process of bubble sort arithmetic in C.  I need some suggestions on improving it.

#include &lt;stdio.h&gt;
#include &lt;Windows.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#define SIZE 20
#define WIDE (SIZE * 2)

void RepaintScreen(int *pData, int count, int p1, int p2)
{
    system("cls");
    char b[(WIDE + 1) * (SIZE)];
    b[0] = '\0';
    for (int i = 0; i &lt; count; i++)
    {
        if (i == p1 || i == p2)
        {
            strcat(b, "--&gt;");
        } else {
            strcat(b, "   ");
        }
        for (int j = 0; j &lt; pData[i]; j++)
        {
            strcat(b, "|");
        }
        strcat(b, "\n");
    }
    printf("%s", b);
}

void BubbleSort(int *pData, int count)
{
    int iTemp;
    for (int i = 0; i &lt; count; i++)
    {
        for (int j = count - 1; j &gt; i; j--)
        {
            if (pData[j] &lt; pData[j - 1])
            {
                iTemp = pData[j];
                pData[j] = pData[j - 1];
                pData[j - 1] = iTemp;
                RepaintScreen(pData, count, i, j); //refresh the screen
                Sleep(10);
            }
        }
    }
}

int main( int argc, char **argv )
{
    int data[SIZE];
    srand(time(NULL));
    //initiate data
    for (int i = 0; i &lt; SIZE; i++)
    {
        data[i] = rand() % WIDE;
    }
    BubbleSort(data, SIZE);
    return 1;
}
Your code works nicely.  

In BubbleSort I would move the definition of iTemp to the point of first use.  The name iTemp is ugly and the 'i' makes me think you are using a type prefix (as does the 'p' in pData). I don't know anyone who thinks that is a good idea - just use temp and data.

In RepaintScreen I don't see the need to buffer the data yourself.  You can just use stdio to buffer it for you:

static void RepaintScreen(const int *data, int count, int p1, int p2)
{
    for (int i = 0; i &lt; count; i++) {
        fputs((i == p1 || i == p2) ? "--&gt;" : "   ", stdout);

        for (int j = 0; j &lt; data[i]; j++) {
            putc('|', stdout);
        }
        putc('\n', stdout);
    }
}


If you do accumulate a string, using strcat is inefficient and prone to buffer overflow. It is inefficient because on each call it must traverse the whole string to find the end. It would be better to keep track of the end of the string yourself.  For example:

static void RepaintScreen(const int *data, int count, int p1, int p2)
{
    system("cls");
    char buf[(WIDE + 1) * (SIZE)];
    char *b = buf;

    for (int i = 0; i &lt; count; i++) {
        if (i == p1 || i == p2) {
            *b++ = '&gt;';
        } else {
            *b++ = ' ';
        }
        for (int j = 0; j &lt; data[i]; j++) {
            *b++ = '|';
        }
        *b++ = '\n';
    }
    *b++ = '\0';
    fputs(buf, stdout);
}


Overflow occurs if you get the size of the buffer size wrong. Avoiding overflow is messy as you must check that there is enough space each time you insert into the buffer and exit sensibly if there is not. Using fputs/putc, as shown above, avoids overruns.