C/Visual C - Lista no funciona porque?

 
Vista:

Lista no funciona porque?

Publicado por SuperIndio (46 intervenciones) el 09/08/2024 01:37:21
Estimados estoy tratando de leer un archivo y ponerlo en una Lista enlazada y despues mostrarla per cuando lo ejecuto me sale

el codigo completo es:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 cc -Wall -o otest6  otest6.c
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
 
#define LMAX_FILE     120
 
struct arrChar  {
       char string[247];
};
 
void GetNameMovim(char * ccnamefile)
{
      memset(ccnamefile, 0, LMAX_FILE*sizeof(ccnamefile[0]));
      memcpy(ccnamefile, getenv("A9_FICHIE"), LMAX_FILE );
      strcat(ccnamefile, "/FICOB.movimientos.txt" );
      return;
}
 
typedef struct nodo {
     char dato[247];
     struct nodo *sig, * ant;
} NODO;
 
 
NODO *crearNodo(char num[247]);
void AppendNodo(NODO **inicio, char num[247]);
 
 
void mostrar(NODO *inicio);
void mostrar2(NODO *inicio);
 
int EliminarFinal(NODO **inicio);
 
int main() {
 
       char ifilename[LMAX_FILE]="txt";
       struct arrChar aux;
       int j=-1;
       char *devf;
 
       // char *dato ;
       NODO *inicio=NULL;
 
       printf("GetNameMovim()\n");
       GetNameMovim(ifilename);
       printf("NameFile: %s\n", ifilename);
       FILE *punFile;
       punFile=fopen(ifilename,"r");
       printf("Exec..fopen() is Okis!\n");
       do {
            j++;
            devf = fgets(aux.string, 247, punFile);
            AppendNodo(&inicio, devf);
            // printf("fgets(%s)\n", aux.string);
       } while (devf!=NULL);
       printf("El archivo tiene %d valores\n",j);
       fclose(punFile);
       /*
        |
        | a partir de aqui se leen los nodos
        |
        */
       mostrar2(inicio);
       return 0;
}
 
 
 
NODO*crearNodo( char dato[247] ) {
     NODO *nuevo=NULL;
     nuevo=(NODO*)malloc(sizeof(NODO));
     if (nuevo!=NULL) {
         strcpy(nuevo->dato, dato);
         nuevo->sig=NULL;
         nuevo->ant=NULL;
     }
     return nuevo;
}
 
 
void AppendNodo( NODO **inicio, char dato[247]) {
     NODO *nuevo=NULL, *aux=*inicio;
     nuevo=crearNodo(dato);
     if(nuevo != NULL) {
         if(aux==NULL) {
             *inicio=nuevo;
             aux=*inicio;
         } else {
             while(aux->sig!=NULL) {
                  aux=aux->sig;
             }
             aux->sig=nuevo;
             nuevo->ant=aux;
             nuevo->sig=NULL;
         }
     }
}
 
 
void mostrar(NODO *inicio) {
      NODO* aux=inicio;
      while(aux !=NULL) {
           printf("%s\n", aux->dato);
           aux=aux->sig;
      }
}
void mostrar2(NODO *inicio) {
      NODO *aux=inicio;
      while(aux->sig!=NULL)
           aux=aux->sig;
      while(aux !=NULL) {
            printf("%s \n", aux->dato);
            aux=aux->ant;
      }
}
 
int EliminarFinal(NODO **inicio) {
      NODO *borrar=NULL;;
      NODO *recorrer=NULL;
      recorrer=*inicio;
      if(recorrer==NULL) {
            printf("No hay elementos en la lista\n");
            return -1;
      }
      while(recorrer->sig!=NULL) {
            borrar = recorrer;
            recorrer= recorrer->sig;
      }
      if(borrar==NULL) {
            borrar = *inicio;
            *inicio = NULL;
            free (borrar);
      } else {
            free(borrar->sig);
            borrar->sig=NULL;
      }
      return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder