hi first look at this code:
Code:
#include <stdio.h>
#include <stdlib.h>
void binary(char byte) {
unsigned char mask = 0x80;
for ( ; mask; mask >>= 1)
putchar(byte & mask ? '1' : '0');
}
int main( void )
{
FILE *fp;
int c;
if ( (fp = fopen("TEXT.TXT", "rb")) == NULL)
{
fprintf(stderr, "Error opening file.");
exit(1);
}
while ((c = fgetc(fp)) != EOF)
{
binary(c);
putchar(' ');
}
putchar('\n');
fclose(fp);
return 0;
}
fgetc reads fp one byte at a time but how can i read two bytes in a row and save them to arrays like this: first and second byte in c[0] and c[1] and after code is executed third and fourth byte in c[0] and c[1] and on... . ( the code was just for example )