Vote count:
0
I am trying to read a binary file containing integers in the binary form. I need to use the open() and read() functions rather than fopen() and the like.
I open my file and try to read it, but i get binary symbols in my output.
char buffer[sizeof(int)];
int file1;
int bytesRead;
file1 = open(argv[1], O_RDONLY);
if(file1 == -1)
{
printf("unable to open file\n");
exit(1);
}
while((bytesRead = read(file1, &buffer, sizeof(buffer))))
{
printf("%d\n", buffer);
}
Can anyone point me in the right direction?
asked 1 min ago
Reading file of binary integers in C using open() and read()
Aucun commentaire:
Enregistrer un commentaire