• Miércoles 15 de Mayo de 2024, 05:51

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - Leber

Páginas: 1 2 [3]
51
C/C++ / Re: Confundido con código en C
« en: Jueves 24 de Marzo de 2011, 22:23 »
Lo siento m0skito, fue un desliz.

Bueno, para orientarte un poco, puedes definir un array de 100 enteros por ejemplo, e ir entrando uno por uno hasta que sea 0.
Podrías postear el codigo que llevas hecho, así podriamos ayudarte mejor.

Saludos

52
C/C++ / Re: Buscar string en un archivo, y obtener datos
« en: Jueves 24 de Marzo de 2011, 17:04 »
Cita de: "m0skit0"
No hay de qué, estamos aquí para compartir lo que sabemos, así que ya sabes, ahora te toca a ti compartir  ;)  :comp:

Intentaremos que así sea =)

53
C/C++ / Re: Buscar string en un archivo, y obtener datos
« en: Jueves 24 de Marzo de 2011, 16:11 »
Hola m0skito.

Si, entiendo que ese es el funcionamiento, que lo que quieres es:

Teniendo una cadena tal que asi: "hola que tal", y que strstr te devuelva un puntero a "que tal" (porque has buscado la primera aparicion de que), lo que le estas diciendo es:

Muestrame lo que sigue a partir de la posicion, p.e: 0x7fffd1573a23, (teniendo en cuenta que ptr apunte a 0x7fffd1573a20). Entonces recibes a partir de 0x7fffd1573a23 hasta final de linea.

Gracias por tu ayuda, me ha quedado bastante claro, y es algo que siempre he tenido algo así así, sabian lo que eran los punteros, pero no los habia manipulado de esta manera, no habia entendido nunca demasiado bien el desplazamiento que podias hacer a traves de la memoria, como ahora.

Saludos y gracias

54
C/C++ / Re: Buscar string en un archivo, y obtener datos
« en: Jueves 24 de Marzo de 2011, 13:51 »
Efectivamente, 4 bytes se pierden con solo unsigned int.  Aunque basta con ponert unsigned long int:


Código: C
  1. int main(void)
  2. {
  3.     char line[] = "Hola que tal estas";
  4.     char *ptr;
  5.  
  6.             printf("Size int-> %ldn", sizeof(unsigned int));
  7.             printf("Size int-> %ldn", sizeof(unsigned long int));
  8.  
  9.             ptr = strstr (line, "que");
  10.             if(ptr != NULL) {
  11.                 printf("%sn", (char*) ((unsigned long int)ptr + strlen("que")) );
  12.             }
  13.             return 0;
  14. }
  15.  
  16.  
  17. test@test:~/c$ ./prueba
  18. Size int-> 4
  19. Size int-> 8
  20.  tal estas
  21.  


Igualmente, tengo otra duda, y es sobre:

Código: C
  1. (char*) ((unsigned long int)ptr + strlen("que"))
  2.  

Sobretodo esta parte:

Código: C
  1. (unsigned long int)ptr
  2.  
. Estas casteando la direccion de memoria, y le sumas 3, que es la longitud de la cadena.

Entonces, si la direccion de ptr empieza en "0x7fffd1573a20" le sumas 3 quedando: "0x7fffd1573a23"  

Es correcto, o me estoy liando?

Saludos, y gracias por las respuestas =)

55
C/C++ / Re: Buscar string en un archivo, y obtener datos
« en: Jueves 24 de Marzo de 2011, 13:01 »
Pues, acabo de copiar tu codigo, y no funciona. Mira:

Código: C
  1. test@sistemes-oscar:~/c$ cat prueba.c
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int main(void)
  7. {
  8.     char line[] = "Hola que tal estas";
  9.     char *ptr;
  10.  
  11.             ptr = strstr (line, "que");
  12.             if(ptr != NULL) {
  13.                 printf("%sn", (char*) ((unsigned int)ptr + strlen("que")) );
  14.             }
  15.             return 0;
  16. }
  17. test@sistemes-oscar:~/c$ gcc -o prueba prueba.c
  18. prueba.c: In function ‘main’:
  19. prueba.c:12: warning: cast from pointer to integer of different size
  20. test@sistemes-oscar:~/c$ ./prueba
  21. Segmentation fault
  22. test@sistemes-oscar:~/c$
  23.  

Me resulta bastante extraño.
Lo mismo, si lo hago en SO de 32 bits, funciona:

Código: C
  1. test@sistemes-test:~$ cat proba.c
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>                                                                                                                                                                  
  5.                                                                                                                                                                                      
  6. int main(void)                                                                                                                                                                        
  7. {                                                                                                                                                                                    
  8.     char line[] = "Hola que tal estas";                                                                                                                                              
  9.     char *ptr;                                                                                                                                                                        
  10.                                                                                                                                                                                      
  11.             ptr = strstr (line, "que");                                                                                                                                              
  12.             if(ptr != NULL) {
  13.                 printf("%sn", (char*) ((unsigned int)ptr + strlen("que")) );
  14.             }
  15.             return 0;
  16. }
  17.  
  18. test@sistemes-test:~$ ./proba
  19.  tal estas
  20. test@sistemes-test:~$
  21.  

En mi maquina, mi SO es de 64 bits, y no funciona, en esta ultima es de 32 bits y funciona. Ambas maquinas tienen la misma version del gcc 4.4.3.
No se ver muy claro por que en 32 si y en 64 no, lo unico que me viene a la cabeza es que los punteros en 64 bits ocupan 8 bytes en lugar de 4 como ocurre en 32, pero... esto no debería afectar en este codigo, no?

Gracias

56
C/C++ / Re: Buscar string en un archivo, y obtener datos
« en: Jueves 24 de Marzo de 2011, 11:05 »
Hola moskito, compilando esto:

Código: C
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int main(void)
  7. {
  8.     char line[] = "Hola que tal estas";
  9.     char *ptr;
  10.  
  11.             ptr = strstr (line, "que");
  12.             if(ptr != NULL) {
  13.                 printf("%sn", (char*) ((unsigned int)ptr + strlen("que")) );
  14.             }
  15.             return 0;
  16. }
  17.  

Me da un warning, y si lo ejecuto da segfault. Si entiendo bien, le estas diciendo "lo que contiene ptr" + "la longitud de que". Y por que se hace un cast a unsigned int? Siento tantas preguntas pero es que estaba leyendo esto ayer, y me pico la curiosidad.

Gracias de antemano

57
C/C++ / Lista doblemente enlazada circular[SOL]
« en: Martes 16 de Diciembre de 2008, 17:52 »
Buenas a todos, tengo una duda al liberar una lista doblemente enlazada circular:

Aqui os adjunto el codigo que tengo:

Código: Text
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct __double_list
  5. {
  6.         int num;
  7.         struct __double_list *next,
  8.                              *prev;
  9. };
  10.  
  11. int __creat_head(struct __double_list **list);
  12. int __insert(struct __double_list **list, int __number);
  13. void show(struct __double_list *head);
  14. void destroy(struct __double_list **list);
  15.  
  16. int
  17. main()
  18. {
  19.  
  20.         struct __double_list *__list = NULL;
  21.         int __number_to_put;
  22.  
  23.         if( (__creat_head(&__list)) != 0)
  24.                 return -1;
  25.  
  26.         for( __number_to_put = 0 ; __number_to_put < 5 ; __number_to_put++)
  27.         {
  28.                 if( (__insert(&__list, __number_to_put)) != 0)
  29.                 {
  30.                         printf("Error de memn");
  31.                         return -1;
  32.                 }
  33.  
  34.         }
  35.  
  36.         show(__list);
  37.         destroy(&__list);
  38.         //show(__list); Es para probar si esta bien liberada
  39.         return 0;
  40.  
  41. }
  42.  
  43. int __creat_head(struct __double_list **list)
  44. {
  45.         *list = (struct __double_list *)malloc(sizeof(struct __double_list));
  46.  
  47.         if(*list == NULL)
  48.         {
  49.                 perror("Error de mem");
  50.                 return -1;
  51.         }
  52.  
  53.         (*list)->next = (*list)->prev = *list;
  54.  
  55.         return 0;
  56. }
  57.  
  58. int __insert(struct __double_list **list, int __number)
  59. {
  60.         struct __double_list *new;
  61.  
  62.         new = (struct __double_list *)malloc(sizeof(struct __double_list));
  63.  
  64.         if(new == NULL)
  65.         {
  66.                 perror("Error new");
  67.                 return -1;
  68.         }
  69.  
  70.         printf("Number-> %dn",__number);
  71.  
  72.  
  73.         new->num = __number;
  74.         new->next = *list;
  75.         new->prev = (*list)->prev;
  76.         (*list)->prev->next = new;
  77.         (*list)->prev = new;
  78.  
  79.         return 0;
  80. }
  81.  
  82. void show(struct __double_list *head)
  83. {
  84.         struct __double_list *node;
  85.  
  86.         node = head->next;
  87.  
  88.         while(node != head)
  89.         {
  90.                 printf("Node num->%dn",node->num);
  91.                 node = node->next;      
  92.         }
  93. }
  94.  
  95. void destroy(struct __double_list **list)
  96. {
  97.         struct __double_list *node, *aux;
  98.  
  99.         node = (*list)->next;
  100.  
  101.         while(node != *list)    
  102.         {
  103.                 aux = node;
  104.                 node = node->next;
  105.                 free(aux);
  106.         }      
  107.         *list = NULL;
  108. }
  109.  

No me convence, porque si vuelvo a mostrar la lista, me muestro 20 veces numeros muy extraños, cuando no deberia de mostrar nada, deberia salir del bucle y ya esta, es por eso que creo que esta mal la funcion de borrar la lista.

A ver si me podeis echar un cable;

Gracias de antemano & saludos


----------------

Ya lo solucione, fue un fallo bastante grave, jeje, al final la funcion quedo asi:

Código: Text
  1. void destroy(struct __double_list **list)
  2. {
  3.         struct __double_list *node, *aux;
  4.  
  5.         node = (*list)->next;
  6.  
  7.         while(node != *list)    
  8.         {
  9.                 aux = node;
  10.                 aux->next->prev = aux->prev;
  11.                 aux->prev->next = aux->next;
  12.                 node = node->next;
  13.                 free(aux);
  14.         }      
  15.         *list = NULL;
  16. }
  17.  

Gracias

58
C/C++ / Saber el tipo de un fichero
« en: Miércoles 10 de Diciembre de 2008, 23:28 »
Buenas señores, bueno, veran, tengo una duda: Como hacer para saber el tipo de fichero
Es decir, lo mismo que hace la utilidad "file" de linux, por ejemplo:

Código: Text
  1.  < /dev/null > file Vendeta.mpg
  2. Vendeta.mpg: MPEG sequence, v1, system multiplex
  3. < /dev/null > file amule_download
  4. amule_download: symbolic link to `.aMule/Incoming/'
  5.  


He buscado en el man, y veo que recoje la informacion de /etc/file/magic, mirando los magic numbers y demas, y me he estado ojeando el archivo, pero no acabo de aclararme.
He probado de buscar el src de la utilidad "file", para fijarme en el codigo y ver como trabaja para saber como puedo hacerlo y, pero no lo encuentro.

Agradeceria cualquier idea, aporte, documento etc..

Gracias de antemano

59
C/C++ / Documentacion FMOX EX
« en: Jueves 30 de Octubre de 2008, 00:05 »
Buenas, escribo esto porque he intentado buscar documentacion, o algun tutorial de fmod Ex, pero solo he encontradoa cerca de fmod3, y era para a ver si alguien podia facilitarme algun link sobre fmod ex, algun manual basico donde se explique su funcionamento, cualquier cosa para empezar en C (si es en cualquier otro lenguage no pasa nada, solo es para ver el funcionamiento, y aprender un poco).

Uso FMOD EX 4.18 bajo linux.

Gracias de antemano

60
C/C++ / Re: Problema con estructuras
« en: Jueves 16 de Octubre de 2008, 21:34 »
Si, ahi tienes la deficion.  Creo que se donde esta el posible fallo:

En la funcion cargar_notas, hago esto para leer las notas del fichero y pasarlas a la estructura:

Código: Text
  1. # while(( r_bytes=read(d_n,p,sizeof(NOTAS)) ) > 0)
  2. #                          {    
  3. #                             p->sig=l;
  4. #                             l=p;
  5. #                             p=inicializa(p);   //si es la ultima vez, l apunta a que? porque p pierde su valor
  6. #                          }
  7. #  
  8. #                          
  9. #                          free(p);
  10.  

Creo que es ahi, ya que en ser la ultima iteracion, inicializamos p, pero ya no quedan mas datos, entonces se pierde ese puntero, no?

Yo diria que si, pero estoy tan desquiciado con esto que quiza veo errores donde no los hay.

Saludos

61
C/C++ / Re: Problema con estructuras
« en: Jueves 16 de Octubre de 2008, 16:21 »
Si, perdona esque pretendia que las funciones principales tuvieran los mismos parametros y devolvieran lo mismo, asi hacer un while y el valor que retorne la funcion menu, pues ir a sea funcion, pero he simplificado el codigo eliminando tonterias para intentar localizar el problema, pero sigo sin dar con ello.

Código: Text
  1. #if !defined(_NOTAS_H)
  2. #define _NOTAS_H
  3.  
  4. int menu(void);
  5.  
  6. typedef struct
  7. {
  8.     int nota_catalan;
  9.     int nota_castellano;
  10.     int nota_mates;
  11.     int nota_ingles;
  12.  
  13. }MATERIAS;
  14.  
  15. typedef struct __notas
  16. {
  17.    
  18.     int trimestre;
  19.     MATERIAS m;
  20.     struct __notas *sig;
  21.  
  22. }NOTAS;
  23. typedef NOTAS *nodo;
  24. typedef NOTAS *lista;
  25.  
  26. int leer_notas(void);
  27. int escribir_nota(void);
  28. int fin(void);
  29.  
  30. lista carga_notas(lista l);
  31. nodo inicializa(nodo p);
  32. int carga_fichero(int nota, int materia, int trimestre);
  33.  
  34.  int(*pfunc[])(void)=
  35. {
  36.     leer_notas,
  37.    escribir_nota,
  38.     fin,
  39.    
  40. };
  41.  
  42. #endif
  43.  
  44.  
  45.  

Código: Text
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "notas.h"
  6. #include <fcntl.h>
  7.  
  8. #define BUFSIZE 1024
  9.  
  10. void mostrar_notas(lista l, int tipox);
  11.  
  12. static int num_malloc=0;
  13. static int num_free=0;
  14.  
  15.  
  16.  
  17. int getint(void)
  18. {
  19.     char c;
  20.     int nbytes;
  21.     char BUFFER[BUFSIZE];
  22.  
  23.  
  24.            nbytes=read(0,&c,1);
  25.  
  26.              if(nbytes != 1)
  27.              {
  28.                  perror("READ ");
  29.                  return -1;
  30.              }
  31.  
  32.              while(strlen(fgets(BUFFER,BUFSIZE,stdin)) > 1)
  33.                  memset(BUFFER,'',sizeof(BUFFER));
  34.              return (c-'0');
  35. }
  36.  
  37. int
  38. main()
  39. {
  40.  
  41.    
  42.     int cod_error;
  43.  
  44.             while(!0)
  45.                if(( cod_error=pfunc[menu()]() ) == -1 )
  46.                     pfunc[2]();
  47.            
  48.     return 0;
  49. }  
  50.  
  51. int
  52. menu(void)
  53. {
  54.  
  55.     int elec=0;
  56.    
  57.  
  58.                  
  59.  
  60.                printf("Agenda de notas-n");
  61.                 printf("ntOpciones:
  62.                           nt1- Leer notas
  63.                           nt2- Escribir nota
  64.                           nt3 -Fn");
  65.  
  66.                   puts("--");
  67.  
  68.                  elec=(getint())-1;
  69.  
  70.  
  71.                          
  72.          
  73.                      
  74.  
  75.     return (elec < 0 || elec > 4 ) ? 4 : elec;
  76. }
  77.  
  78. int
  79. escribir_nota(void)
  80. {
  81.    
  82.    
  83.     unsigned int m=0;
  84.    unsigned int t=0;
  85.     unsigned int n=0;
  86.    int cod_error;
  87.  
  88.                ptr_wr=carga_fichero;
  89.        
  90.                 printf("Materia:n");
  91.                     printf("nt1- Catalan
  92.                               nt2- Castellano
  93.                               nt3- Matematicas
  94.                               nt4- Inglesn");
  95.  
  96.  
  97.                     printf("Escoga->n");
  98.                m=getint();
  99.  
  100.                     printf("Nota:n");              
  101.  
  102.                     n=getint();
  103.  
  104.                printf("Trimestre:n");
  105.                    
  106.                     t=getint();
  107.              
  108.  
  109.                     if( (cod_error=(carga_fichero(n,m,t))  == -1)
  110.                     {
  111.                         fprintf(stderr,"Error al escribir en el ficheron");
  112.                         return -1;
  113.                     }
  114.  
  115.                
  116.     return 0;
  117. }
  118.  
  119.  
  120. int
  121. mostrar_tipos(void)
  122. {
  123.     int opcion=0;
  124.  
  125.           printf("nt1- Visualizar por asignatura
  126.                     nt2- Visualizar media de una asignatura
  127.                     nt3- Visualizar media de todas las asignaturas
  128.                     n");
  129.  
  130.             opcion=getint();
  131.  
  132.             return opcion;
  133.  
  134. }
  135.  
  136.  
  137.  
  138. void mostrar_total_notas(lista l, unsigned int assig)
  139. {
  140.     nodo p;
  141.  
  142.        p=l;
  143.  
  144.             while(p)
  145.               {
  146.                   if(assig == 0)
  147.                   {
  148.                      
  149.                      // if ( p->m.nota_catalan != 0)
  150.                           printf("> %dn",p->m.nota_catalan);
  151.                      
  152.                    }
  153.                                   else if(assig == 1)
  154.                   {
  155.                       //if(p->m.nota_castellano != 0)
  156.                       printf("> %dn",p->m.nota_castellano);
  157.                   }
  158.                   else if(assig == 2)
  159.                   {
  160.                       //if(p->m.nota_mates != 0)
  161.                       printf("> %dn",p->m.nota_mates);
  162.                   }
  163.                   else
  164.                   {
  165.                       //if(p->m.nota_ingles != 0)
  166.                       printf("> %dn",p->m.nota_ingles);
  167.                   }
  168.  
  169.                   p=p->sig;
  170.               }
  171.  
  172.              
  173.  
  174. }
  175.  
  176.  
  177.  
  178. float media_assignaturas(lista l, int materia_t)
  179. {
  180.  
  181.     nodo p;
  182.     int n_notas=0;
  183.     float n_media=0;
  184.  
  185.  p=l;
  186.  
  187.  
  188.  
  189.                                                if(materia_t != 0)
  190.                            {
  191.                          while(p)
  192.                          {
  193.                                                     if(materia_t == 1)
  194.                           {
  195.                              if(p->m.nota_catalan != 0)
  196.                               {
  197.                                  
  198.                                 n_media+=p->m.nota_catalan;
  199.                                 n_notas++;
  200.                               }
  201.                           }
  202.                           else if(materia_t == 2)
  203.                           {
  204.                               if(p->m.nota_castellano != 0)
  205.                               {
  206.                                   n_media+=p->m.nota_castellano;
  207.                                   n_notas++;
  208.                               }
  209.                           }
  210.                           else if(materia_t == 3)
  211.                           {
  212.                               if(p->m.nota_mates != 0)
  213.                               {
  214.                                   n_media+=p->m.nota_mates;
  215.                                   n_notas++;
  216.                               }
  217.                           }
  218.                           else
  219.                           {
  220.                               if(p->m.nota_ingles != 0)
  221.                               {
  222.                                   n_media+=p->m.nota_ingles;
  223.                                                                  n_notas++;
  224.                                                           }
  225.                           }
  226.                            p=p->sig;
  227.                          }
  228.  
  229.                 }
  230.  
  231.                      
  232.  
  233.     return (n_media/n_notas);
  234.  
  235. }
  236.  
  237.  
  238.  
  239. void _liberar_mem_struct(lista l)
  240. {
  241.     nodo p;
  242.  
  243.  
  244.          while(l)
  245.          {
  246.               p=l;
  247.               l=p->sig;
  248.               free(p);
  249.               num_free++;
  250.            
  251.        }
  252.           printf("Free-> %dtMalloc-> %dn",num_free,num_malloc);
  253. }
  254.  
  255.  
  256. void
  257. mostrar_notas(lista l, int tipox)
  258. {
  259.  char *[]={"Catalan","Castellano",
  260.                                  "Matematicas","Ingles"};
  261. unsigned int _numero_assig=0;
  262. unsigned int assig=0;  
  263. float media_t;
  264.                                                             switch(tipox)
  265.                                         {  
  266.                                        default: case 1:
  267.                                                    
  268.                                                                                           while( _numero_assig < 4 )
  269.                                                {
  270.                                                   printf("Notas [%s]:n",asignaturas[_numero_assig]);
  271.                                                   mostrar_total_notas(l,_numero_assig);
  272.                                                   _numero_assig++;
  273.                                               }  
  274.                                                                                  break;
  275.                  
  276.                                                    
  277.                                 case 2:      
  278.                                                                                          printf("Assignatura:n");
  279.                                                  assig=getint();
  280.  
  281.                                                   if(assig < 1 || assig > 4 )
  282.                                                   {
  283.                                                       fprintf(stderr,"Asignatura fuera de rangon");
  284.                                                       return;
  285.                                                   }
  286.  
  287.                                                                                   media_t=media_assignaturas(l,assig);
  288.  
  289.                                          printf(">Media [%s] ->%4.2fn",asignaturas[assig-1],media_t);
  290.  
  291.                                              break;
  292.  
  293.                                   case 3:
  294.                                          while(assig++ < 4)
  295.                                           {
  296.                                           media_t=media_assignaturas(l,assig);
  297.                                           printf("> Media [%s] ->  %4.2fn",asignaturas[assig-1],media_t);
  298.                                                                                   }
  299.                                             break;
  300.  
  301.                                                    }
  302.  
  303.                                
  304.                                    
  305.                  
  306. }
  307.  
  308.  
  309. int
  310. leer_notas(void)
  311. {
  312.  
  313.   lista l=NULL;
  314.  
  315.            if(( l=carga_notas(l) ) != NULL)
  316.             {
  317.               mostrar_notas(l, mostrar_tipos());
  318.            _liberar_mem_struct(l);
  319.                 return 0;
  320.              }
  321.  
  322.              
  323.  
  324.   return -1;
  325. }
  326.  
  327.  
  328.  
  329. int fin(void)
  330. {
  331.    
  332.     exit(0);
  333. }
  334.  
  335.  
  336.  
  337. int carga_fichero(int nota, int materia, int trimestre)
  338. {
  339.   int df;
  340.    nodo p;  
  341.  
  342.    
  343.  
  344.            
  345.                   if((df=open("notas.dat",O_WRONLY | O_APPEND | O_CREAT,0600)) == -1)
  346.                   {
  347.                       perror("2notas.dat");
  348.                       return -1;
  349.                   }
  350.              
  351.        
  352.             p=inicializa(p);
  353.  
  354.             if(!p)
  355.             return -1;
  356.  
  357.                                          if( materia == 1)
  358.                          p->m.nota_catalan=nota;
  359.                      else if( materia == 2 )
  360.                          p->m.nota_castellano=nota;
  361.                      else if( materia == 3)
  362.                          p->m.nota_mates=nota;
  363.                      else if( materia == 4)
  364.                          p->m.nota_ingles=nota;
  365.                      else
  366.                      {
  367.                          fprintf(stderr,"Materia [%d] desconocidan",materia);
  368.                          return -1;
  369.                      }
  370.  
  371.                      p->trimestre=trimestre;
  372.  
  373.                
  374.  
  375.                     write(df,p,sizeof(NOTAS));
  376.  
  377.                     free(p);
  378.                                     num_free++;
  379.                     close(df);
  380.  
  381.         return 0;
  382.            
  383. }
  384.  
  385.  
  386. lista carga_notas(lista l)
  387. {
  388.         nodo p;
  389.         int d_n;
  390.         int r_bytes=0;
  391.        
  392.  
  393.                       if(( d_n = open("notas.dat",O_RDONLY)) == -1)
  394.                 {
  395.                                    perror("datos.dat");
  396.                    return NULL;
  397.                 }
  398.  
  399.              
  400.                          p=inicializa(p);
  401.                
  402.                          if(!p)
  403.                            return NULL;
  404.                      
  405.                          while(( r_bytes=read(d_n,p,sizeof(NOTAS)) ) > 0)
  406.                          {    
  407.                             p->sig=l;
  408.                             l=p;
  409.                             p=inicializa(p);
  410.                          }
  411.  
  412.                          
  413.                          free(p);
  414.                          num_free++;
  415.                          close(d_n);
  416.                      
  417.               return l;
  418.  
  419. }
  420.  
  421.  
  422. nodo inicializa( nodo p)
  423. {
  424.        num_malloc++;
  425.        p=(nodo)malloc(sizeof(NOTAS));
  426.  
  427.        return p;        
  428.  
  429. }
  430.  
  431.  
  432.  

Aun asi, he arreglado un par de cosillas y tampoco, me repite la nota de la primera asignatura que entro, no se donde más mirar.

Gracias

62
C/C++ / Re: Problema con estructuras
« en: Jueves 16 de Octubre de 2008, 14:52 »
Primero de todo gracias por responder, y gastar un poco de tiempo, aqui van las declaraciones y luego la aplicacion:

Decir que, solo se repite la primera asignatura que escribo una nota, es decir, si arranco el programa y le inserto un 4 a matematicas, me mostrara un 4, como si el programa escribiese un 4 siempre en la nota, las demas asignaturas me las muestro bien.

notas.h
Código: Text
  1. #if !defined(_NOTAS_H)
  2. #define _NOTAS_H
  3.  
  4.  
  5. typedef struct
  6. {
  7.     int nota_catalan;
  8.         int nota_castellano;
  9.     int nota_mates;
  10.     int nota_ingles;
  11.  
  12. }MATERIAS;
  13.  
  14. typedef struct __notas
  15. {
  16.     int trimestre;
  17.     MATERIAS m;
  18.     struct __notas *sig;
  19.  
  20. }NOTAS;
  21.  
  22.  
  23. typedef NOTAS *nodo;
  24. typedef NOTAS *lista;
  25.  
  26. int menu();
  27. int leer_notas(lista l);
  28. int escribir_nota(lista l);
  29. int escribir_trabajo(lista l);
  30. int total_tp(lista l);
  31. int fin(lista l);
  32.  
  33.  
  34. void mostrar_notas(lista l, int tipox);
  35. int getint();
  36. int mostrar_tipos();
  37. int carga_fichero(int nota, int materia, int trimestre);
  38. void carga_notas(lista l);
  39. void _liberar_mem_struct(lista l);
  40.  
  41. int(*pfunc[])(lista l)=
  42. {
  43.     leer_notas,
  44.    escribir_nota,
  45.     escribir_trabajo,
  46.     total_tp,
  47.     fin,
  48.    
  49. };
  50.  
  51. #endif
  52.  
  53.  

Apli:

Código: Text
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "notas.h"
  6. #include <fcntl.h>
  7.  
  8. #define BUFSIZE 1024
  9.  
  10. void mostrar_notas(lista l, int tipox);
  11.  
  12. int getint(void)
  13. {
  14.     char c;
  15.     int nbytes;
  16.     char BUFFER[BUFSIZE];
  17.  
  18.  
  19.            nbytes=read(0,&c,1);
  20.  
  21.              if(nbytes != 1)
  22.              {
  23.                  perror("READ ");
  24.                  return -1;
  25.              }
  26.  
  27.              nbytes=read(0,BUFFER,BUFSIZE-1);
  28.              memset(BUFFER,'',BUFSIZE);  
  29.            
  30.              return (c-'0');
  31. }
  32.  
  33. int
  34. main()
  35. {
  36.  
  37.     lista l=NULL;
  38.     int cod_error;
  39.  
  40.             while(!0)
  41.                if(( cod_error=pfunc[menu()](l) ) == -1 )
  42.                     pfunc[4](l);
  43.            
  44.     return 0;
  45. }    
  46. int
  47. menu(void)
  48. {
  49.  
  50.     int elec=0;
  51.  
  52.                printf("Agenda de notas-n");
  53.                 printf("ntOpciones:
  54.                           nt1- Leer notas
  55.                           nt2- Escribir nota
  56.                         nt3- Escribir trabajo
  57.                           nt4- Total tp
  58.                           nt5 -Fn");
  59.  
  60.                   puts("--");
  61.  
  62.                  elec=(getint())-1;
  63.          
  64.                      
  65.  
  66.     return (elec < 0 || elec > 4 ) ? 4 : elec;
  67. }
  68.  
  69. int
  70. escribir_nota(lista l)
  71. {
  72.    
  73.     int (*ptr_wr)();
  74.     unsigned int m=0;
  75.    unsigned int t=0;
  76.     unsigned int n=0;
  77.    int cod_error;
  78.  
  79.                ptr_wr=carga_fichero;
  80.        
  81.                 printf("Materia:n");
  82.                     printf("nt1- Catalan
  83.                               nt2- Castellano
  84.                               nt3- Matematicas
  85.                               nt4- Inglesn");
  86.  
  87.  
  88.                     printf("Escoga->n");
  89.                m=getint();
  90.  
  91.                     printf("Nota:n");              
  92.  
  93.                     n=getint();
  94.  
  95.                printf("Trimestre:n");
  96.                    
  97.                     t=getint();
  98.              
  99.  
  100.                     if( (cod_error=((*ptr_wr)(n,m,t)) ) == -1)
  101.                     {
  102.                         fprintf(stderr,"Error al escribir en el ficheron");
  103.                         return -1;
  104.                     }
  105.  
  106.                
  107.     return 0;
  108. }
  109.  
  110. int
  111. mostrar_tipos(void)
  112. {
  113.     int opcion=0;
  114.  
  115.           printf("nt1- Visualizar por asignatura
  116.                     nt2- Visualizar media de una asignatura
  117.                     nt3- Visualizar media de todas las asignaturas
  118.                     n");
  119.  
  120.             opcion=getint();
  121.  
  122.             return opcion;
  123.  
  124. }
  125.  
  126. void mostrar_total_notas(lista l, unsigned int assig)
  127. {
  128.     nodo p;
  129.  
  130.        p=l;
  131.  
  132.             while(p)
  133.               {
  134.                   if(assig == 0)
  135.                   {
  136.                      
  137.                       if ( p->m.nota_catalan != 0)
  138.                       {
  139.                           printf("NOTAS CATALANn");
  140.                          printf("> %dn",p->m.nota_catalan);
  141.                       }
  142.                   }
  143.               else if(assig == 1)
  144.                   {
  145.                       if(p->m.nota_castellano != 0)
  146.                       printf("> %dn",p->m.nota_castellano);
  147.                   }
  148.                   else if(assig == 2)
  149.                   {
  150.                       if(p->m.nota_mates != 0)
  151.                       printf("> %dn",p->m.nota_mates);
  152.                   }
  153.                   else
  154.                   {
  155.                       if(p->m.nota_ingles != 0)
  156.                       printf("> %dn",p->m.nota_ingles);
  157.                   }
  158.  
  159.                   p=p->sig;
  160.               }
  161.  
  162.            
  163.  
  164. }
  165.  
  166. float media_assignaturas(lista l, int materia_t)
  167. {
  168. nodo p;
  169. int n_notas=0;
  170. float n_media=0;
  171.  
  172.  p=l;
  173.  
  174.  printf("Mat->%dn",materia_t);
  175.  
  176.                 if(materia_t != 0)
  177.                      {
  178.                          while(p)
  179.                          {
  180.                     if(materia_t == 1)
  181.                           {
  182.                              if(p->m.nota_catalan != 0)
  183.                               {
  184.                                   printf("NOTAS CATALANan");
  185.                                 n_media+=p->m.nota_catalan;
  186.                                 n_notas++;
  187.                               }
  188.                           }
  189.                           else if(materia_t == 2)
  190.                           {
  191.                               if(p->m.nota_castellano != 0)
  192.                               {
  193.                                   n_media+=p->m.nota_castellano;
  194.                                   n_notas++;
  195.                               }
  196.                           }
  197.                           else if(materia_t == 3)
  198.                           {
  199.                               if(p->m.nota_mates != 0)
  200.                               {
  201.                                   n_media+=p->m.nota_mates;
  202.                                   n_notas++;
  203.                               }
  204.                           }
  205.                           else
  206.                           {
  207.                               if(p->m.nota_ingles != 0)
  208.                                                          n_notas++;
  209.                                                   }
  210.                           }
  211.                            p=p->sig;
  212.                          }
  213.  
  214.                 }
  215.  
  216.                      
  217.  
  218.     return (n_media/n_notas);
  219.  
  220. }
  221.  
  222. void
  223. mostrar_notas(lista l, int tipox)
  224. {
  225. const char *const asignaturas[]={"Catalan","Castellano",
  226.                                  "Matematicas","Ingles"};
  227. unsigned int _numero_assig=0;
  228. unsigned int assig=0;  
  229. float media_t;
  230.                         switch(tipox)
  231.                              {  
  232.                                 default: case 1:
  233.                                                    
  234.                                     while( _numero_assig < 4 )
  235.                                                {
  236.                                                   printf("Notas [%s]:n",asignaturas[_numero_assig]);
  237.                                                   mostrar_total_notas(l,_numero_assig);
  238.                                                   _numero_assig++;
  239.                                                 }  
  240.                                       break;
  241.                  
  242.                                                    
  243.                                 case 2:      
  244.                                       printf("Assignatura:n");
  245.                                                  assig=getint();
  246.  
  247.                                                   if(assig < 1 || assig > 4 )
  248.                                                   {
  249.                                                       fprintf(stderr,"Asignatura fuera de rangon");
  250.                                                       return;
  251.                                                   }
  252.  
  253.                                       media_t=media_assignaturas(l,assig);
  254.  
  255.                 printf(">Media [%s] %4.2fn",asignaturas[assig-1],media_t);
  256.  
  257.                                              break;
  258.  
  259.                                   case 3:
  260.                                                   while(assig++ < 4)
  261.                                                   {
  262.                                                       media_t=media_assignaturas(l,assig);
  263.                                                       printf("> Media [%s] -> %4.2fn",asignaturas[assig-1],media_t);
  264.                                       }
  265.                                                   break;
  266.  
  267.                              }
  268.  
  269.                                 _liberar_mem_struct(l);
  270.                                    
  271.                  
  272. }
  273.  
  274. int
  275. leer_notas(lista l)
  276. {
  277.  
  278.   nodo p;
  279.  
  280.            l=NULL;
  281.            
  282.              
  283.          
  284.            if(( l=carga_notas() ) != NULL)
  285.             {
  286.                     /*p=l;
  287.  
  288.                     while(p)
  289.                     {
  290.                        
  291.                        
  292.                        
  293.                     }*/
  294.  
  295.                   mostrar_notas(l, mostrar_tipos());
  296.                 return 0;
  297.              }
  298.  
  299.   return -1;
  300. }
  301.  
  302. int fin(lista l)
  303. {
  304.     _liberar_mem_struct(l);
  305.  
  306.     exit(0);
  307. }
  308.  
  309. int carga_fichero(int nota, int materia, int trimestre)
  310. {
  311.     int df;
  312.    nodo p;  
  313.    static int veces=0;
  314.     printf("CARGA FICHEROn");
  315.  
  316.            
  317.                   if((df=open("notas.dat",O_WRONLY | O_APPEND)) == -1)
  318.                   {
  319.                       perror("2notas.dat");
  320.                       return -1;
  321.                   }
  322.              
  323.        
  324.             p=inicializa(p);
  325.  
  326.             if(!p)
  327.                 return -1;
  328.  
  329.                 if( materia == 1)
  330.                          p->m.nota_catalan=nota;
  331.                      else if( materia == 2 )
  332.                          p->m.nota_castellano=nota;
  333.                      else if( materia == 3)
  334.                          p->m.nota_mates=nota;
  335.                      else if( materia == 4)
  336.                          p->m.nota_ingles=nota;
  337.                      else
  338.                      {
  339.                          fprintf(stderr,"Materia [%d] desconocidan",materia);
  340.                          return -1;
  341.                      }
  342.  
  343.                      p->trimestre=trimestre;
  344.  
  345.                
  346.  
  347.                     write(df,p,sizeof(NOTAS));
  348.  
  349.                     free(p);
  350.                 num_free++;
  351.             close(df);
  352.  
  353.         return 0;
  354.            
  355. }
  356.  
  357. lista carga_notas(void)
  358. {
  359.         nodo p;
  360.         int d_n;
  361.         int r_bytes=0;
  362.         lista l=NULL;
  363.         int indice=0;
  364.  
  365.                       if(( d_n = open("notas.dat",O_RDONLY)) == -1)
  366.                             {
  367.                                   perror("2datos.dat");
  368.                                   return NULL;
  369.                            }
  370.  
  371.              
  372.                          p=inicializa(p);
  373.                
  374.                          if(!p)
  375.                            return NULL;
  376.                      
  377.                          while(( r_bytes=read(d_n,p,sizeof(NOTAS)) ) > 0)
  378.                          {    
  379.                             p->sig=l;
  380.                             l=p;
  381.                             p=inicializa(p);
  382.                          }
  383.                      
  384.                          free(p);
  385.                          num_free++;
  386.                          close(d_n);
  387.                      
  388.               return l;
  389.  
  390. }
  391. nodo inicializa( nodo p)
  392. {
  393.        num_malloc++;
  394.        p=(nodo)malloc(sizeof(NOTAS));
  395.  
  396.        return p;      
  397.  
  398. }  
  399.  
  400.  

Gracias antemano

63
C/C++ / Problema con estructuras
« en: Jueves 16 de Octubre de 2008, 00:53 »
Buenas, tengo un problema:

Ayer hice una pequeña agenda de notas para practicar un poco, un fichero binario con estructuras, todo funciona bien menos al mostrarme los datos, que hay algunas notas que se repiten( esto no se si es problema de al mostrar datos, o al escribirlos en el fichero)

Por ejemplo:

Yo le inserto en Catalan la nota 1 y hago un listado de notas y me muestra:


Código: Text
  1. Notas [Catalan]:
  2. > 1
  3. Notas [Castellano]:
  4. Notas [Matematicas]:
  5. Notas [Ingles]:
  6.  


Luego inserto la nota 5 en matematicas y al hacer el listado, sorpresa:



Código: Text
  1. Notas [Catalan]:
  2. > 1
  3. > 1
  4. Notas [Castellano]:
  5. Notas [Matematicas]:
  6. > 5
  7. Notas [Ingles]:
  8.  


Como ven, salen 2 "1", uno lo puse yo, pero y el otro? He revisado una y otra vez el codigo y no encuentro nada que pueda ser:

Las estructuras son estas:

Código: Text
  1.  
  2. typedef struct
  3. {
  4.     int nota_catalan;
  5.     int nota_castellano;
  6.     int nota_mates;
  7.     int nota_ingles;
  8.  
  9. }MATERIAS;
  10.  
  11. typedef struct __notas
  12. {
  13.    
  14.     int trimestre;
  15.     MATERIAS m;
  16.     struct __notas *sig;
  17.  
  18. }NOTAS;
  19.  


Las funciones de escribir, leer son estas:

Escribe en un fichero la estructura con las notas


 
Código: Text
  1. int
  2. carga_fichero(int nota, int materia, int trimestre)
  3. {
  4.  
  5. int df;
  6.    nodo p;
  7.  
  8.               if(( df = open("notas.dat",O_WRONLY | O_APPEND | O_CREAT,0600)) == -1)
  9.               {
  10.                       perror("notas.dat");
  11.                  return -1;
  12.               }
  13.  
  14.               p=inicializa(p);
  15.  
  16.               if(!p)
  17.                       return -1;
  18.  
  19.               if( materia == 1)
  20.                       p->m.nota_catalan=nota;
  21.                   else if( materia == 2 )
  22.                       p->m.nota_castellano=nota;
  23.                   else if( materia == 3)
  24.                       p->m.nota_mates=nota;
  25.                   else if( materia == 4)
  26.                       p->m.nota_ingles=nota;
  27.                   else
  28.                   {
  29.                       fprintf(stderr,"Materia [%d] desconocidan",materia);
  30.                       return -1;
  31.                   }
  32.                  
  33.                  
  34.                   p->trimestre=trimestre;
  35.                  
  36.                   write(df,p,sizeof(NOTAS));
  37.  
  38.               free(p);
  39.  
  40.               close(df);
  41.  
  42.       return 0;
  43.  
  44. }
  45.  


Lee fichero y devuelve estructura:



Código: Text
  1. lista
  2. carga_notas(void)
  3. {
  4.     nodo p;
  5.     int d_n;
  6.     int r_bytes;
  7.     lista l=NULL;
  8.     int indice=0;
  9.                       if(( d_n = open("notas.dat",O_RDONLY)) == -1)
  10.                             {
  11.                                 perror("2datos.dat");
  12.                                 return NULL;
  13.                             }
  14.                            
  15.                             p=inicializa(p);
  16.                            
  17.                             if(!p)
  18.                                 return NULL;
  19.                            
  20.                             while(( r_bytes=read(d_n,p,sizeof(NOTAS)) ) > 0)
  21.                      {
  22.                                 p->sig=l;
  23.                                 l=p;
  24.                                 p=inicializa(p);
  25.                             }
  26.  
  27.                      free(p);
  28.  
  29.                      close(d_n);
  30.  
  31.            return l;
  32.  
  33. }
  34.  


Muestra notas




Código: Text
  1. void mostrar_total_notas(lista l, unsigned int assig)
  2. {
  3.     nodo p;
  4.  
  5.        p=l;
  6.  
  7.             while(p)
  8.               {
  9.                   if(assig == 0)
  10.                   {
  11.                      
  12.                       if ( p->m.nota_catalan != 0)
  13.                       {
  14.                           printf("NOTAS CATALANn");
  15.                          printf("> %dn",p->m.nota_catalan);
  16.                       }
  17.                   }
  18.               else if(assig == 1)
  19.                   {
  20.                       if(p->m.nota_castellano != 0)
  21.                       printf("> %dn",p->m.nota_castellano);
  22.                   }
  23.                   else if(assig == 2)
  24.                   {
  25.                       if(p->m.nota_mates != 0)
  26.                       printf("> %dn",p->m.nota_mates);
  27.                   }
  28.                   else
  29.                   {
  30.                       if(p->m.nota_ingles != 0)
  31.                       printf("> %dn",p->m.nota_ingles);
  32.                   }
  33.  
  34.                   p=p->sig;
  35.               }
  36. }
  37.  


Yo no le veo nada extraño, y de hecho no se porque me lo hace..., a ver si alguien puede arrojar un poco de luz, porque estoy algo preucupado.

Muchas gracias

64
C/C++ / Re: Problemas Con El Mastermind
« en: Viernes 9 de Mayo de 2008, 00:14 »
A mi me compila bien( uso gcc), lo unico da un warning por la funcion gets( es bastante insegura esta funcion).

Código: Text
  1. gcc foro.c -o foro
  2. /tmp/ccqKN9zq.o: In function &#96;main':
  3. foro.c:(.text+0x1d8): warning: the &#96;gets' function is dangerous and should not be used.
  4.  
  5.  

65
C/C++ / Error Con Free()
« en: Martes 25 de Marzo de 2008, 17:50 »
Buenas, estaba haciendo un programilla que buscara ficheros acabdos en ~, pero hay un problema. Primero les enganchare el codigo y luego lo comento:

Código: Text
  1. void buscar(char *home,const char *destino)
  2. {
  3.   DIR *dirp;
  4.   struct dirent *dir;
  5.   int fd,i,de,ds,nbytes;
  6.   char *duplicado;
  7.   char *pathdest;
  8.   char *pathhome;
  9.   char buffer[BUFSIZ];
  10.  
  11.                         if((dirp=opendir(home))==NULL)
  12.                           {
  13.                             perror(home);
  14.                             exit(-1);
  15.                           }
  16.  
  17.            
  18.        
  19.           if((pathdest=(char *)calloc(80,sizeof(char)))==NULL)
  20.                            {
  21.                               perror(&#34;malloc&#34;);
  22.                               exit(-1);
  23.                            }
  24.  
  25.                          if((pathhome=(char *)calloc(80,sizeof(char)))==NULL)
  26.                            {
  27.                               perror(&#34;malloc home&#34;);
  28.                               exit(-1);
  29.                            }
  30.                      printf(&#34;memoria reservada&#092;n&#34;);
  31.      
  32.                     while((dir=readdir(dirp))!=NULL)
  33.                       {
  34.        
  35.                          
  36.                
  37.                printf(&#34;empezando while&#092;n&#34;);
  38.        
  39.                          duplicado=strdup(dir-&#62;d_name);
  40.  
  41.                             for(i=strlen(dir-&#62;d_name)-1;i&#62;0;i--)
  42.                                if(duplicado[i]=='~')
  43.                            {
  44.                                  
  45.                             pathhome=(char *)realloc(pathhome,((strlen(home))+((strlen(dir-&#62;d_name)))));
  46.                                   pathdest=(char *)realloc(pathdest,((strlen(destino))+((strlen(duplicado)))));
  47.              
  48.                                
  49.                                    sprintf(pathhome,&#34;%s/%s&#34;,home,duplicado);
  50.                              sprintf(pathdest,&#34;%s/%s&#34;,destino,duplicado);
  51.                                    
  52.                
  53.                                     if((fd=creat(pathdest,0666))==-1)
  54.                                 {
  55.                                 perror(pathdest);
  56.                           exit(-1);
  57.                          }
  58.            
  59.                        if((de=open(pathhome,O_RDONLY))==-1)
  60.                                      {
  61.                     perror(pathhome);
  62.                                       exit(-1);
  63.                          }
  64.                    
  65.                        if((ds=open(pathdest,O_WRONLY))==-1)
  66.                          {
  67.                                       perror(pathdest);
  68.                                       exit(-1);
  69.                                      }
  70.                      
  71.                      while((nbytes=read(de,buffer,sizeof(buffer)))&#62;0)
  72.                        if((write(ds,buffer,nbytes))!=nbytes)
  73.                                    fprintf(stderr,&#34;Error de escritura en %s&#092;n&#34;,ds);
  74.          
  75.        
  76.                         close(de);
  77.                                     close(ds);
  78.  
  79.                        if((unlink(pathhome))==-1)
  80.                         {
  81.                                       perror(pathhome);
  82.                                       exit(-1);
  83.                                     }
  84.                         // printf(&#34;petando aqui&#092;n&#34;);
  85.                                      
  86.            
  87.                         }
  88.                                //printf(&#34;hola&#092;n&#34;);
  89.                                
  90.                    printf(&#34;repitiendo while&#092;n&#34;);
  91.              }
  92.       printf(&#34;acabando&#092;n&#34;);
  93.      
  94.  
  95.   closedir(dirp);
  96.   free(source);
  97.  printf(&#34;source liberado&#092;n&#34;);
  98.   free(destdir);
  99.   printf(&#34;des liberado&#092;n&#34;);
  100.   free(pathdest);
  101.   printf(&#34;pathdest liberado&#092;n&#34;);
  102.   free(duplicado);
  103.   printf(&#34;duplicado liberado&#092;n&#34;);
  104.   free(pathhome);
  105.   printf(&#34;pathhome liberado&#092;n&#34;);
  106.   }
  107.  

El error esta en free(pathhome), ya que me peta ahi, cuando libero la memoria de pathhome. Como ven primero le asigno 80 bytes al empezar el programa, luego cada vez que se encuentra un fichero acabado en ~, le reasigno la lontigud del directorio mas la del nombre del fichero, y bueno, todo va bien hasta el momento de liberar la memoria que acaba con un:

Código: Text
  1. *** glibc detected *** ./backups: free(): invalid next size (fast): 0x0804c0c8 ***
  2. ======= Backtrace: =========
  3. /lib/i686/cmov/libc.so.6[0xb7e9b915]
  4. /lib/i686/cmov/libc.so.6(cfree+0x90)[0xb7e9f380]
  5. ./backups[0x8049092]
  6. ./backups[0x8048cb0]
  7. /lib/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7e46450]
  8. ./backups[0x80487f1]
  9. ======= Memory map: ========
  10. 08048000-0804a000 r-xp 00000000 08:06 639238 /home/null/mis_programas/backups
  11. 0804a000-0804b000 rw-p 00001000 08:06 639238 /home/null/mis_programas/backups
  12. 0804b000-0806c000 rw-p 0804b000 00:00 0 [heap]
  13. b7d00000-b7d21000 rw-p b7d00000 00:00 0
  14. b7d21000-b7e00000 ---p b7d21000 00:00 0
  15. b7e15000-b7e21000 r-xp 00000000 08:02 354860 /lib/libgcc_s.so.1
  16. b7e21000-b7e22000 rw-p 0000b000 08:02 354860 /lib/libgcc_s.so.1
  17. b7e2f000-b7e30000 rw-p b7e2f000 00:00 0
  18. b7e30000-b7f77000 r-xp 00000000 08:02 370991 /lib/i686/cmov/libc-2.7.so
  19. b7f77000-b7f78000 r--p 00147000 08:02 370991 /lib/i686/cmov/libc-2.7.so
  20. b7f78000-b7f7a000 rw-p 00148000 08:02 370991 /lib/i686/cmov/libc-2.7.so
  21. b7f7a000-b7f7d000 rw-p b7f7a000 00:00 0
  22. b7f89000-b7f8c000 rw-p b7f89000 00:00 0
  23. b7f8c000-b7fa8000 r-xp 00000000 08:02 354818 /lib/ld-2.7.so
  24. b7fa8000-b7faa000 rw-p 0001b000 08:02 354818 /lib/ld-2.7.so
  25. bfb95000-bfbaa000 rw-p bfb95000 00:00 0 [stack]
  26. ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
  27. Abortado
  28.  

El error es : " free(): invalid next size (fast): 0x0804c0c8", y como ven todo va bien hasta que se intenta liberar su memoria:

acabando
source liberado
des liberado
pathdest liberado
duplicado liberado



Peta ahi. La verdad no se que estoy haciendo mal, si alguien pudiera ayudarme... se lo agradeceria mucho.

Gracias de antema

Páginas: 1 2 [3]