elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  ayuda porfa
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda porfa  (Leído 2,211 veces)
MarSalem

Desconectado Desconectado

Mensajes: 6


Ver Perfil
ayuda porfa
« en: 25 Mayo 2020, 21:44 pm »

tengo este ejercicio.
realizar un programa que cree un archivo binario con bytes aleatorios, garantizando que en alguna parte del programa se encuentre la secuencia de 7 bytes a8 5c 60 70 70 af ef.

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define N 8
  6.  
  7. int main(){
  8.  
  9. FILE * FP, *FPAUX;
  10. int i, ENCONTRADO;
  11. int byte;
  12.  
  13. srand(time(NULL));
  14.  
  15.  
  16. if ( (FP = fopen ("EJ","wb")) == NULL ) {
  17. printf("\n\n ERROR APERTURA DE ARCHIVO \n\n") ;
  18. exit(1);
  19.  
  20. }
  21.  
  22. printf("\n\t\t INGRESE BYTE A ALMACENAR \n\n");
  23. for ( i = 0 ; i < N ; i++ ) {
  24. byte = rand() % 65536;
  25. printf("\n\n\t %x \n", byte);
  26.  
  27. fwrite ( &byte , sizeof(byte) , 1 , FP );
  28. }
  29.  
  30. fclose(FP);
  31.  
  32. if ( (FP = fopen ("EJ","rb")) == NULL ) {
  33. printf("\n\n ERROR APERTURA DE ARCHIVO LECTURA \n\n") ;
  34. exit(1);
  35. };
  36.  
  37. if ( (FPAUX = fopen ("EJAUX","wb")) == NULL ) {
  38. printf("\n\n ERROR APERTURA DE ARCHIVO ESCRITURA \n\n") ;
  39. exit(1);
  40. };
  41.  
  42. fread ( &byte , sizeof(byte) , 1 , FP );
  43. while ( ! feof(FP)) {
  44. if ( byte == 43100)
  45. fseek(FP, sizeof(byte) , SEEK_SET);
  46. if (byte == 26992)
  47. fseek(FP, sizeof(byte), SEEK_CUR);
  48. if(byte == 28847)
  49. fseek(FP, sizeof(byte), SEEK_CUR);
  50. if(byte == 239)
  51. ENCONTRADO = 1;
  52.  
  53.  
  54. fwrite ( &byte, sizeof(byte) , 1 , FPAUX );
  55.  
  56. fread ( &byte , sizeof(byte) , 1 , FP );
  57. }
  58.  
  59.  
  60. fclose(FP);
  61. fclose(FPAUX);
  62.  
  63.  
  64. /*  ELIMINAMOS BD Y RENOMBRAMOS BDAUX COMO BD  */
  65. remove("EJ") ;
  66. rename( "EJAUX" , "EJ" );
  67.  
  68.  
  69. return 0 ;
  70.  
  71. }

ese es lo que hice hasta ahora pero el if no me funciona, no se si estoy usando mal el fseek


MOD: Utiliza etiquetas de Código GeSHi para el código


« Última modificación: 26 Mayo 2020, 02:05 am por YreX-DwX » En línea

insta @marsquarepants
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda porfa! No lee los dvd
Multimedia
Evo 2 2,208 Último mensaje 23 Enero 2006, 11:44 am
por Evo
Una ayuda porfa
Ingeniería Inversa
catalinilla 3 2,273 Último mensaje 16 Octubre 2011, 19:05 pm
por catalinilla
ayuda porfa
Programación C/C++
saserromdp 6 2,432 Último mensaje 6 Marzo 2012, 21:50 pm
por Anastacio
No-Ip ayuda porfa
Programación Visual Basic
elmatador2 9 3,058 Último mensaje 7 Abril 2015, 03:03 am
por elmatador2
Ayuda porfa!
Seguridad
ignacio69 2 2,103 Último mensaje 24 Abril 2020, 12:51 pm
por El_Andaluz
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines