Why does the following C code produce negative numbers as output? And how do I prevent this from happening?
#include <stdio.h>
int main()
{
int i;
char buf[1024];
for (i = 0; i < 1024; i++)
buf[i] = i%256;
for (i=0; i<1024; i++) {
printf("%d ", buf[i]);
if (i%32==31)
printf("\n");
}
}