|
| 1 | +#include <stdio.h> |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +void printbin(int number){ |
| 6 | + int i; |
| 7 | + for(i = 128; i > 0; i >>= 1){ |
| 8 | + if((number & i) == i){ |
| 9 | + printf("1"); |
| 10 | + } |
| 11 | + else{ |
| 12 | + printf("0"); |
| 13 | + } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +int main(){ |
| 20 | + int contador; |
| 21 | + char puntero[(1024*2)]; |
| 22 | + int bytes; |
| 23 | + int bytesmaximo; |
| 24 | + |
| 25 | + int pesolectura; |
| 26 | + FILE * archivolectura; |
| 27 | + char * nombrearchivolectura; |
| 28 | + |
| 29 | + int pesoescritura; |
| 30 | + FILE * archivoescritura; |
| 31 | + char * nombrearchivoescritura; |
| 32 | + |
| 33 | + FILE *file; |
| 34 | + |
| 35 | + bytes = 1; |
| 36 | + bytesmaximo = (1024*2); |
| 37 | + nombrearchivolectura = "ORIGINAL.JPG"; |
| 38 | + printf("\nLECTURA DE '%s' ",nombrearchivolectura); |
| 39 | + archivolectura = fopen(nombrearchivolectura,"rb"); |
| 40 | + if(archivolectura == NULL){ |
| 41 | + printf("\nNo se logro abrir el archivo para leer\n"); |
| 42 | + return -1; |
| 43 | + } |
| 44 | + |
| 45 | + fseek(archivolectura, 0, SEEK_END); |
| 46 | + pesolectura = ftell(archivolectura); |
| 47 | + if(pesolectura>(1024*2)){ |
| 48 | + printf("\nEL archivo debe ser de 2 KBytes o menos\n"); |
| 49 | + return -1; |
| 50 | + } |
| 51 | + fclose (archivolectura); |
| 52 | + |
| 53 | + archivolectura = fopen(nombrearchivolectura,"rb"); |
| 54 | + if(archivolectura == NULL){ |
| 55 | + printf("\nNo se logro abrir el archivo para leer\n"); |
| 56 | + return -1; |
| 57 | + } |
| 58 | + |
| 59 | + pesolectura = fread(puntero, bytes, bytesmaximo, archivolectura); |
| 60 | + if(pesolectura==0){ |
| 61 | + printf("\nEl archivo esta sin datos\n"); |
| 62 | + return -1; |
| 63 | + } |
| 64 | + |
| 65 | + printf("CON %d Bytes\n", pesolectura); |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + bytes = 1; |
| 70 | + bytesmaximo = (1024*2); |
| 71 | + nombrearchivoescritura = "COPIA.JPG"; |
| 72 | + printf("ESCRITURA DE '%s' ",nombrearchivoescritura); |
| 73 | + |
| 74 | + archivoescritura = fopen(nombrearchivoescritura,"wb"); |
| 75 | + if(archivoescritura == NULL){ |
| 76 | + printf("\nNo se logro abrir el archivo para escribir\n"); |
| 77 | + return -1; |
| 78 | + } |
| 79 | + |
| 80 | + pesoescritura = fwrite(&puntero, sizeof(unsigned char), pesolectura, archivoescritura); |
| 81 | + if(pesoescritura == 0){ |
| 82 | + printf("\nNo se logro escribir datos\n"); |
| 83 | + return -1; |
| 84 | + } |
| 85 | + printf("CON %d Bytes\n\n", pesoescritura); |
| 86 | + |
| 87 | + //FILE *file; |
| 88 | + |
| 89 | + file = fopen("COPIADEBYTES.JPG","ab+"); |
| 90 | + |
| 91 | + for(contador = 0; contador < (pesolectura / sizeof(unsigned char)); contador++){ |
| 92 | + |
| 93 | + /*Indice de Bytes, Hexadecimal, Binario*/ |
| 94 | + printf("Byte[%d] = 0X%02x ", contador, (int)((unsigned char)puntero[contador])); |
| 95 | + printbin((int)((unsigned char)puntero[contador])); |
| 96 | + //printf(" %d",(int)puntero[contador]); //ASCII |
| 97 | + printf("\n"); |
| 98 | + |
| 99 | + //FILE *file = fopen("copia por bytes.jpg","ab+"); |
| 100 | + /*if(file == NULL){ |
| 101 | + printf("\ncopia de byteas a 'copia por bytes.jpg' interrumpida\n"); |
| 102 | + return -1; |
| 103 | + }*/ |
| 104 | + fwrite(&puntero[contador], 1, 1, file); |
| 105 | + //fclose(file); |
| 106 | + |
| 107 | + } |
| 108 | + fclose(file); |
| 109 | + printf("\nESCRITURA DE 'COPIADEBYTES.JPG' CON %d Bytes\n\n",pesoescritura); |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + fclose (archivolectura); |
| 114 | + fclose (archivoescritura); |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + return 0; |
| 119 | +} |
0 commit comments