I have a problem

I have this problem, when im trying to save data (char type) into a List with pointers, those data doesnt get saved. Somebody can help me?

Im using Borland 5.02

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
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <fstream.h>
#include <stdlib.h>
typedef struct sistem{
		      char nombre[15];
                      struct sistem *sigarchivo;
                     }tipoSis;
typedef sistem *pNodo;
typedef sistem *Sistema;
void CreateFile(Sistema *, sistem);
void Dir(Sistema r);

void main()
{inicio:
 Sistema root = NULL;
 tipoSis archivo;
 char parametro[50];
 cout<<"$ ";
 cin>>parametro;
 if (strstr(parametro,"createfile"))
   {
    cin>>archivo.nombre;
    CreateFile(&root,archivo);
    goto inicio;
   }
 else if (strcpy(parametro,"dir"))
 	{
    Dir(root);
    goto inicio;
   }
}

int CarpetaVacia(Sistema root)
{
 return (root == NULL);
}

void CreateFile(Sistema *r, sistem n)
{
  pNodo nuevo=new sistem;
  pNodo otroArch;
  if (nuevo)
     strcpy(nuevo->nombre,n.nombre);
  if (CarpetaVacia(*r))
     {
       nuevo->sigarchivo=*r;
       *r=nuevo;
       cout<<"First node created \n";
     }
  else
    {
      otroArch=*r;
      while (otroArch->sigarchivo)
      	{
          otroArch=otroArch->sigarchivo;
         }

      nuevo->sigarchivo=otroArch->sigarchivo;
      otroArch->sigarchivo=nuevo;
      cout<<"Another node created \n";
    }
}

void Dir(Sistema root)
{
 pNodo punt = root;
 if (CarpetaVacia(root))
 	{
    cout<<"C:/RAIZ \n Empty";
   }
 else
 	{
    while (punt)
    	{
       cout<<"C:/RAIZ \n"<< punt->nombre;
       punt = punt->sigarchivo;
      }
    cout<<endl;
   }
}
> Im using Borland 5.02
Yes, that is a problem.
Your code does not follow the standard of 1998 (bad headers, lack of namespace, main must return int). Please correct it.

Your goto is unnecessary and confusing. If you manage to follow it, you'll realize that you are setting root=NULL all the time, losing the list.

You may want to consider using a List class to manage the nodes, and avoid all those memory leaks that you are having.
thanks i solved the problem, i move the goto to another place and now works!

i know that using Borland is the problem, but i cant use other compiler, our class work with Borland and my teacher doesn't let use another one.
Topic archived. No new replies allowed.