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.
Because char in the C language is exactly 1 byte. So it's logical to write in the file byte by byte.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With