Answer the question
In order to leave comments, you need to log in
Error reading binary file?
#include <stdio.h>
#include <malloc.h>
#include "library.h"
int main() {
FILE *in;
queue q;
queue_init(&q);
in=fopen("input.bin","w");
int *array,array_quantity,st=0,num;
scanf("%i",&array_quantity);
array=(int*)malloc(array_quantity* sizeof(int));
for (int i=0;i<array_quantity;i++)
scanf("%i",&array[i]);
fwrite(array, sizeof(int),array_quantity,in);
free(array);
fclose(in);
in=fopen("input.bin","r");
while((num=fgetc(in))!=EOF){
// queue_push(&q,num);
printf("%i ",num);
}
//while (!q.quantity){
// printf("%i",q.quantity);
//}
fclose(in);
return 0;
}
Answer the question
In order to leave comments, you need to log in
fwrite(array, sizeof(int),array_quantity,in); ... while((num=fgetc(in))!=EOF){ // queue_push(&q,num); printf("%i ",num); }
at the beginning I add the numbers 1 2 3 (example) and from the file I get 1000 2000 3000
What's the matter?
array_quantity
elements of size to the file sizeof(int)
, and read from the file character by character?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question