#include #include int main (int argc, char *argv[]) { FILE *fp; int i = 0, numdisplay; short int data; if ((argc > 3) || (argc < 2)) { printf("DISPLAYS THE FIRST N ELEMENTS OF 16 BIT INTEGER BINARY FILE\n"); printf("N default = 32\n"); printf("Usage: %s binary-file [N]\n", argv[0]); exit(1); } if (argc == 3) { numdisplay=atoi(argv[2]); } else { numdisplay = 32; } if ((fp=fopen(argv[1],"rb"))==NULL){ printf("Cannot open file %s",argv[1]); exit(1); } while (i++ < numdisplay) { if (fread(&data, sizeof(short int), 1, fp) != 1) { if (!feof(fp)) { printf("Read Error\n"); exit(1); } else i = numdisplay; } else printf("%hd\t",data); } printf("\n"); fclose(fp); }