Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <sys/time.h>
  5. #include <time.h>
  6. #define LONGITUD 15
  7. #define TOPE 5
  8. #define COPIA 200
  9. #define VECTOR 25
  10. #define TRUE 1
  11. #define FALSE 0
  12.  
  13.  
  14. /*  Declaracion de Funciones */
  15.  
  16. int busqueda_sasuke(int x ,int y );
  17.  
  18.  
  19. /* Estructuras */
  20.  
  21. struct amigo
  22. {
  23.        char nombre_amigo [LONGITUD] ;
  24.      //  int poder ; //Sea el poder medido de 1 a 6
  25.        
  26. };
  27.  
  28. struct celda
  29. {
  30.        char nombre[LONGITUD] ;
  31.        int poder ;
  32.        int vida ; // Sea vida 1 , no vida , celda Kyuubi
  33.        
  34. };
  35.  
  36. struct villano
  37. {
  38.     int poder; //Villano tiene poder medido de 1 a 6
  39.    
  40. };
  41.  
  42.  
  43. struct celda casilla ;
  44. struct villano oroshimaru ;
  45. struct amigo amigos;
  46.  
  47.    
  48.  
  49. /* Bloque principal */
  50.  
  51. int main ()
  52. {  
  53.    
  54.     srand(time(NULL));
  55.     FILE *fichero=NULL  ; //iniciar sin basura
  56.     char *save=NULL ;
  57.     char *new_casilla=NULL ;
  58.     char *copia=NULL ;
  59.     int contador , i, j ,horizontal,empieza,end ;
  60.     char array[VECTOR] ;
  61.     unsigned int tam;
  62.     int vidanaruto=3;  //Vida inicial
  63.     int vidacelda=0;
  64.     int sasuke_found=FALSE ; //cuando sasuke es encontrado cambia a TRUE
  65.     int vid,arch_lei; //pato gore
  66.     char *lista;
  67.     char nombre[10],vida[6];
  68.     int poder;
  69.    
  70.    
  71.     /* Manejo del fichero */
  72.     fichero=fopen("naruto.txt" , "r");
  73.    
  74.     if(fichero!=NULL)       //fseek() to the end, use ftell() to get the size.
  75.     {//inicio if1
  76.    
  77.         if(fseek(fichero,0, SEEK_END)==0)      
  78.         { //inicio if2
  79.        
  80.             tam = ftell(fichero)-8;
  81.            
  82.             copia=calloc(100 , sizeof(char) );
  83.  
  84.             save=calloc(100 , sizeof(char) );   // *(size2));   //Use calloc() to make it a few characters bigger than the file.
  85.  
  86.             fseek(fichero, 0 ,SEEK_SET);     // fseek() to the beginning
  87.  
  88.             horizontal = fread(save,sizeof(char),tam,fichero);     //Use a single fread() call to grab the whole thing into your array.
  89.                                                                   //size2 = size;
  90.             if(horizontal != 0)
  91.                save[++horizontal] = '\0';
  92.            
  93.             else
  94.                 fputs("ERROR",stderr);
  95.            
  96.            
  97.         } //fin if2
  98.        
  99.     }//fin if1
  100.  
  101.    /* printf("Hacia que casilla desea ir  : ");
  102.     scanf("%d" , &casilla)
  103.  
  104.  
  105.     /*prueba*/
  106.    /*
  107.     for(i=0 ; i<tam ; i++)
  108.     printf("%c" , save[i] ) ;
  109.  
  110.     /*recorrer el arreglo*/
  111.        /*esto recorrera el arreglo caracter por caracter */
  112.        
  113.     for(i=0; i<tam ; i++)
  114.     {//inicio for recorrer
  115.               if ( save[i]== '(' ) //empieza a leer la casilla en contenido
  116.                     empieza=i ; // j=(contenido
  117.            
  118.               if (save[i]== ')') //termina de leer la casilla
  119.               {//inicio if casilla
  120.              
  121.                     end=TRUE ;
  122.                    
  123.                     new_casilla=malloc(sizeof(char)); //Se crea una nueva celda estructura celda , espacio estructura celda
  124.                    
  125.                     if (end==TRUE)
  126.                     {  //inicio if(end)
  127.                    
  128.                                    for (j=empieza ; j<i ;j++) //Recorrer el contenido desde ( hasta )
  129.                                    { //inicio for j
  130.                                        
  131.                                       if ( save [j] == ',' )                                      
  132.                                            copia[j-empieza]= ' ' ;
  133.                                            
  134.                                       else
  135.                                            copia[j-empieza]=save[j];
  136.  
  137.                                              
  138.                                    printf("%c" , copia[j] ) ;   //FINES EXPERIMENTALES
  139.                                  
  140.                                    } //fin for j
  141.                                  
  142.                                    printf("\n %i", sscanf(copia , "%s %d %s" , nombre, &poder , vida) );  //Prueba de lectura  
  143.                                    //Deberia tirar 2
  144.                                    
  145.                                   if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) != EOF )
  146.                                   {//inicio if != EOF
  147.                                  
  148.                                             if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 1 ) /*se leen 3 elementos (Nombre , Poder , Vida) */
  149.                                             {
  150.                                                    vidanaruto=vidanaruto+1 ;
  151.                                                        
  152.                                             }
  153.                                  
  154.                                             else if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 2 )  /*Se leen 2 (Nombre , poder ) */
  155.                                             {
  156.                                                    printf("Hola2");
  157.                                             }
  158.                                  
  159.                                             else if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 3 ) /*Se lee 1 elemento (vida) */
  160.                                             {                                                                  /*Celda Ky*/
  161.                                                   vidanaruto=vidanaruto+1 ;
  162.                                             }
  163.                                    
  164.                                             else
  165.                                             {
  166.                                                  printf("\n Error de lectura");
  167.                                             }
  168.                                              
  169.                                   }//fin if != EOF
  170.                                  
  171.                                   else
  172.                                   { //inicio else == EOF
  173.                                  
  174.                                    printf("\n Error de lectura EOF");
  175.                                    
  176.                                   } //fin else ==EOF
  177.                                                                                                                    
  178.                    } //fin if (end)
  179.                                  
  180.               }//fin if casilla
  181.              
  182.     }//fin for recorrer
  183.    
  184.  
  185.  
  186.  
  187.  
  188.  
  189.     getchar();
  190.  
  191.  
  192. return 0;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement