ho scritto il seguente programma
2 file in gioco e 1 funzione void.codice:#include <stdio.h> #define BLOCKSIZE 512 typedef char DATA; void scanInBinaryFile( char *, char * ); int main(){ char nomeF1[20] = {"in.txt"}; char nomeF2[20] = {"binary.txt"}; scanInBinaryFile( nomeF1, nomeF2 ); } void scanInBinaryFile( char *nomeFile1, char *nomeFile2 ){ FILE *f1; f1=fopen( nomeFile1, "rb"); if (f1!=NULL){ DATA myArray[BLOCKSIZE]; int index; int intFread; FILE *f2; f2=fopen(nomeFile2,"w+"); while ( (intFread = fread( myArray, sizeof(DATA), BLOCKSIZE, f1 ))>0 ){ for( index = 0; index < BLOCKSIZE; index++){ if(f2!=NULL){ fprintf( f2, "%c", myArray[index]); } else printf("\n----\nErrore durante l'apertura del file con fopen()\n----\n"); fprintf( f2, "\n --- %d --- \n", intFread ); } } fclose(f1); fclose(f2); } else printf("\n----\nErrore durante l'apertura del file con fopen()\n----\n"); }
la funzione prende il primo argomento come nome del file f1 che andrà a leggere ed interpretare in binario poi scriverà l'equivalente del binario in char in un secondo file f2.
il file in.txt è molto semplice, è parte di una tabella ASCII
dopo l'esecuzione mi viene fuori un file del generecodice:A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79 P 80 Q 81 R 82 S 83 T 84 U 85 V 86 W 87 X 88 Y 89 Z 90
a me piacerebbe leggere il file in binario, cioé senza una codifica ASCII, solo bit/byte, siccome è la prima volta che voglio leggere un file in questo modo, dove sbaglio?codice:A --- 179 --- --- 179 --- 6 --- 179 --- 5 --- 179 --- --- 179 --- --- 179 --- --- 179 --- B --- 179 --- --- 179 --- 6 --- 179 --- 6 --- 179 --- --- 179 --- --- 179 --- --- 179 --- C --- 179 --- --- 179 --- 6 --- 179 --- 7 --- 179 --- --- 179 --- --- 179 --- --- 179 --- D --- 179 --- --- 179 --- 6 --- 179 --- 8 --- 179 --- --- 179 --- --- 179 --- --- 179 --- E --- 179 --- --- 179 --- 6 --- 179 --- 9 --- 179 --- --- 179 --- --- 179 --- --- 179 --- F --- 179 --- --- 179 --- 7 --- 179 --- 0 --- 179 --- --- 179 --- --- 179 --- --- 179 --- G --- 179 --- --- 179 --- 7 --- 179 --- 1 --- 179 --- --- 179 --- --- 179 --- --- 179 --- H --- 179 --- --- 179 --- 7 --- 179 --- 2 --- 179 --- --- 179 --- --- 179 --- --- 179 --- I --- 179 --- --- 179 --- 7 --- 179 --- 3 --- 179 --- --- 179 --- --- 179 --- --- 179 --- J --- 179 --- --- 179 --- 7 --- 179 --- 4 --- 179 --- --- 179 --- --- 179 --- --- 179 --- K --- 179 --- --- 179 --- 7 --- 179 --- 5 --- 179 --- --- 179 --- --- 179 --- --- 179 --- L --- 179 --- --- 179 --- 7 --- 179 --- 6 --- 179 --- --- 179 --- --- 179 --- --- 179 --- M --- 179 --- --- 179 --- 7 --- 179 --- 7 --- 179 --- --- 179 --- --- 179 --- --- 179 --- N --- 179 --- --- 179 --- 7 --- 179 --- 8 --- 179 --- --- 179 --- --- 179 --- --- 179 --- O --- 179 --- --- 179 --- 7 --- 179 --- 9 --- 179 --- --- 179 --- --- 179 --- --- 179 --- P --- 179 --- --- 179 --- 8 --- 179 --- 0 --- 179 --- --- 179 --- --- 179 --- --- 179 --- Q --- 179 --- --- 179 --- 8 --- 179 --- 1 --- 179 --- --- 179 --- --- 179 --- --- 179 --- R --- 179 --- --- 179 --- 8 --- 179 --- 2 --- 179 --- --- 179 --- --- 179 --- --- 179 --- S --- 179 --- --- 179 --- 8 --- 179 --- 3 --- 179 --- --- 179 --- --- 179 --- --- 179 --- T --- 179 --- --- 179 --- 8 --- 179 --- 4 --- 179 --- --- 179 --- --- 179 --- --- 179 --- U --- 179 --- --- 179 --- 8 --- 179 --- 5 --- 179 --- --- 179 --- --- 179 --- --- 179 --- V --- 179 --- --- 179 --- 8 --- 179 --- 6 --- 179 --- --- 179 --- --- 179 --- --- 179 --- W --- 179 --- --- 179 --- 8 --- 179 --- 7 --- 179 --- --- 179 --- --- 179 --- --- 179 --- X --- 179 --- --- 179 --- 8 --- 179 --- 8 --- 179 --- --- 179 --- --- 179 --- --- 179 --- Y --- 179 --- --- 179 --- 8 --- 179 --- 9 --- 179 --- --- 179 --- --- 179 --- --- 179 --- Z --- 179 --- --- 179 --- 9 --- 179 --- 0 --- 179 --- u --- 179 ---

Rispondi quotando