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

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: struct en c en: 27 Noviembre 2015, 21:55 pm
tengo problemas  con la siguente funcion.
la funcion tiene que ordenar de forma ascendente o descendentes   y no me ardena.



Código
  1.  
  2. void agregar_nodo(nodo_t**p,char *ruta)
  3. {
  4.  char*pal=(char*)malloc(strlen(ruta));
  5.  nodo_t*nuevo;
  6.  nodo_t*actual;
  7.  nodo_t*anterior;
  8.  strcpy(pal,ruta);
  9. nuevo=(nodo_t*)malloc(sizeof(nodo_t));
  10.  nuevo->filename=pal;
  11.  nuevo->sig=NULL;
  12.  if(*p==NULL)
  13.  {
  14.    *p=nuevo;
  15.  }
  16.  else
  17.  {
  18.    actual=*p;
  19.   anterior=NULL;
  20.  while((actual!=NULL)&&(ruta>actual->filename))
  21.  {
  22.    anterior=actual;
  23.    actual=actual->sig;
  24.  }
  25.  if(anterior==NULL)
  26.  {
  27.    nuevo->sig=*p;
  28.    *p=nuevo;
  29.  }
  30.  else
  31.   {
  32.       anterior->sig=nuevo;
  33.       nuevo->sig=actual;
  34.   }
  35.  }
  36. }
  37.  
  38.  
2  Programación / Programación C/C++ / Re: struct en c en: 27 Noviembre 2015, 15:57 pm
Ok muchas gracias
3  Programación / Programación C/C++ / Re: struct en c en: 27 Noviembre 2015, 12:22 pm
gracias  class_OpenGL.
yo ise de esta forma y me ando igual megustaria q lo revisen si tiene algun error.
desde ya muchas gracias.




************************************************************************************************************************

#include<stdio.h>
#include<string.h>
#include<stdlib.h>


typedef struct  Nodo{
              char *filename;
              struct Nodo*sig;
            }nodo_t;

void agregar_nodo(nodo_t **p,char* ruta)
{
  char *pal;
  nodo_t *nuevo;
  nodo_t *aux;
  pal=(char*)malloc(strlen(ruta)+1);
  strcpy(pal,ruta);
  nuevo=(nodo_t*)malloc(sizeof(nodo_t));
 
  nuevo->filename=pal;
  nuevo->sig=NULL;

  if(*p==NULL)
    *p=nuevo;
  else
  {
    aux=*p;
    while(aux->sig!=NULL)
     aux=aux->sig;
    aux->sig=nuevo;
  }
}


void mostrar_lista(nodo_t *p)
{
  while(p!=NULL)
  { printf(". %s\n",p->filename);
    p=p->sig;
  }
}

void borrar_todas_lista(nodo_t*p)
{
  nodo_t*borrar=NULL;
  while(p!=NULL)
  {
    borrar=p;
    p=p->sig;
    free(borrar);
  }
}


int main(void)
{
  nodo_t *lista=NULL;
  char *dato=(char*)malloc(1);
  int i;
 
for (i=0;i<3;i++){
   printf("ingrese el dato de la lista\n");
   scanf("%c",dato);
   while(getchar()!='\n');
    agregar_nodo(&lista, dato);
   }
  printf("\n");
   printf("muestra lista final: \n");
   mostrar_lista(lista);
  printf("\n");
  borrar_todas_lista(lista);
  printf("\n");
   printf("muestra lista borrar: \n");
   mostrar_lista(lista);
  printf("\n");
  return 0;
}
4  Programación / Programación C/C++ / struct en c en: 26 Noviembre 2015, 23:06 pm
hola como están.
tengo problemas con esta etructura en agregar no. el problema es que no me almacena en en char *filename.
tampoco puedo cambiar de formato de agregar nodo.
desde ya muchas gracias.




#include<stdio.h>
#include<string.h>
#include<stdlib.h>


typedef struct  Nodo{
                                  char *filename;
              struct Nodo*sig;
}nodo_t;

void agregar_nodo(nodo_t**p,char* ruta)
{
 
  nodo_t* nuevo;
   nodo_t*aux;
  nuevo=(nodo_t*)malloc(sizeof(nodo_t));
  nuevo->filename=ruta;
  nuevo->sig=NULL;
  printf("*es:%c\n",ruta);
 
  printf("***es:%c\n",nuevo->filename);
  if(*p==NULL)
  {
    *p=nuevo;
  }
  else
  {
    aux=*p;
    while(aux->sig!=NULL)
    {
      aux=aux->sig;
    }
    aux->sig=nuevo;
  }
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines