Why we use a char array to create a buffer in the memory instead of a int array and if int array can be used to create the buffer,how to get the output from it ?
int main()
{
char buffer[100];
fread(buffer,sizeof(int),4,stdin);
int i=0;
while(i<4)
{
printf ("%d,\n",buffer[i]);
i=i+1;
}
}
Very simply: we use a char array if we want to read bytes.
Either text strings, or (more generally), binary objects.
A “byte” is usually 1/4 the size of an “int”.
Moreover, socket “read” and “write” counts are byte counts. By longstanding convention, they expect byte buffers.
‘Hope that helps!