write a binary file c
FILE *write_ptr;
write_ptr = fopen("test.bin","wb"); // w for write, b for binary
fwrite(buffer,sizeof(buffer),1,write_ptr); // write 10 bytes from our buffer
write a binary file c
FILE *write_ptr;
write_ptr = fopen("test.bin","wb"); // w for write, b for binary
fwrite(buffer,sizeof(buffer),1,write_ptr); // write 10 bytes from our buffer
file binari c
/*
Mette a 0 il massimo elemento di un vettore.
*/
#include<stdlib.h>
#include<stdio.h>
int main() {
FILE *fd;
int res;
int x;
int max; /* massimo trovato finora */
int posmax; /* posizione del massimo nel file */
/* apre il file */
fd=fopen("test.dat", "r+");
if( fd==NULL ) {
perror("Errore in apertura del file");
exit(1);
}
/* ciclo di lettura */
max=0;
while(1) {
res=fread(&x, sizeof(int), 1, fd);
if( res!=1 )
break;
if( x>max ) {
max=x;
posmax=ftell(fd)-sizeof(int);
}
}
/* torna nella posizione del massimo
e ci scrive sopra 0 */
fseek(fd, posmax, SEEK_SET);
x=0;
fwrite(&x, sizeof(int), 1, fd);
/* chiude il file */
fclose(fd);
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us