Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <sys/time.h>
- #include <time.h>
- #define LONGITUD 15
- #define TOPE 5
- #define COPIA 200
- #define VECTOR 25
- #define TRUE 1
- #define FALSE 0
- /* Declaracion de Funciones */
- int busqueda_sasuke(int x ,int y );
- /* Estructuras */
- struct amigo
- {
- char nombre_amigo [LONGITUD] ;
- // int poder ; //Sea el poder medido de 1 a 6
- };
- struct celda
- {
- char nombre[LONGITUD] ;
- int poder ;
- int vida ; // Sea vida 1 , no vida , celda Kyuubi
- };
- struct villano
- {
- int poder; //Villano tiene poder medido de 1 a 6
- };
- struct celda casilla ;
- struct villano oroshimaru ;
- struct amigo amigos;
- /* Bloque principal */
- int main ()
- {
- srand(time(NULL));
- FILE *fichero=NULL ; //iniciar sin basura
- char *save=NULL ;
- char *new_casilla=NULL ;
- char *copia=NULL ;
- int contador , i, j ,horizontal,empieza,end ;
- char array[VECTOR] ;
- unsigned int tam;
- int vidanaruto=3; //Vida inicial
- int vidacelda=0;
- int sasuke_found=FALSE ; //cuando sasuke es encontrado cambia a TRUE
- int vid,arch_lei; //pato gore
- char *lista;
- char nombre[10],vida[6];
- int poder;
- /* Manejo del fichero */
- fichero=fopen("naruto.txt" , "r");
- if(fichero!=NULL) //fseek() to the end, use ftell() to get the size.
- {//inicio if1
- if(fseek(fichero,0, SEEK_END)==0)
- { //inicio if2
- tam = ftell(fichero)-8;
- copia=calloc(100 , sizeof(char) );
- save=calloc(100 , sizeof(char) ); // *(size2)); //Use calloc() to make it a few characters bigger than the file.
- fseek(fichero, 0 ,SEEK_SET); // fseek() to the beginning
- horizontal = fread(save,sizeof(char),tam,fichero); //Use a single fread() call to grab the whole thing into your array.
- //size2 = size;
- if(horizontal != 0)
- save[++horizontal] = '\0';
- else
- fputs("ERROR",stderr);
- } //fin if2
- }//fin if1
- /* printf("Hacia que casilla desea ir : ");
- scanf("%d" , &casilla)
- /*prueba*/
- /*
- for(i=0 ; i<tam ; i++)
- printf("%c" , save[i] ) ;
- /*recorrer el arreglo*/
- /*esto recorrera el arreglo caracter por caracter */
- for(i=0; i<tam ; i++)
- {//inicio for recorrer
- if ( save[i]== '(' ) //empieza a leer la casilla en contenido
- empieza=i ; // j=(contenido
- if (save[i]== ')') //termina de leer la casilla
- {//inicio if casilla
- end=TRUE ;
- new_casilla=malloc(sizeof(char)); //Se crea una nueva celda estructura celda , espacio estructura celda
- if (end==TRUE)
- { //inicio if(end)
- for (j=empieza ; j<i ;j++) //Recorrer el contenido desde ( hasta )
- { //inicio for j
- if ( save [j] == ',' )
- copia[j-empieza]= ' ' ;
- else
- copia[j-empieza]=save[j];
- printf("%c" , copia[j] ) ; //FINES EXPERIMENTALES
- } //fin for j
- printf("\n %i", sscanf(copia , "%s %d %s" , nombre, &poder , vida) ); //Prueba de lectura
- //Deberia tirar 2
- if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) != EOF )
- {//inicio if != EOF
- if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 1 ) /*se leen 3 elementos (Nombre , Poder , Vida) */
- {
- vidanaruto=vidanaruto+1 ;
- }
- else if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 2 ) /*Se leen 2 (Nombre , poder ) */
- {
- printf("Hola2");
- }
- else if (sscanf(copia , "%s %d %s" , nombre, &poder , vida) == 3 ) /*Se lee 1 elemento (vida) */
- { /*Celda Ky*/
- vidanaruto=vidanaruto+1 ;
- }
- else
- {
- printf("\n Error de lectura");
- }
- }//fin if != EOF
- else
- { //inicio else == EOF
- printf("\n Error de lectura EOF");
- } //fin else ==EOF
- } //fin if (end)
- }//fin if casilla
- }//fin for recorrer
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement