Título: problema con manejo de nodos en linux Publicado por: abaadoon en 10 Febrero 2016, 20:12 pm ayuda tengo un problema con este codigo al compilar en gcc
#include<stdio.h> #include<stdlib.h> void insertarnodoinicio(); void insertarnodoalfinal(); void insertarentrenodos(); void eliminarnodoinicio(); void eliminarnodofinal(); void eliminarentredosnodos(); void buscarnumero(); void mostrarnodo(); struct dato{ dato *psig; int numero; }; dato *cab=NULL; dato *n=NULL; dato *aux=NULL; dato *p=NULL; dato *q; int x,pos,numerodenodos=0,opc; main() { do{ printf("\n************************* ELIGE UNA OPCION **********************************\n\n"); printf(" 1.-Insertar Un Nodo al Inicio\n"); printf(" 2.-Insertar Un Nodo al Final\n"); printf(" 3.-Insertar entre dos Nodos\n"); printf(" 4.-Mostrar Lista\n"); printf(" 5.-Buscar Nodo\n"); printf(" 6.-Eliminar Nodo al Inicio\n"); printf(" 7.-Eliminar Nodo Final\n"); printf(" 8.-Eliminar Entre dos nodos\n"); printf(" 9.-Salir\n"); printf("\n\nTeclee su opcion: "); scanf("%d",&opc); switch(opc){ case 1: insertarnodoinicio(); break; case 2: insertarnodoalfinal(); break; case 3: insertarentrenodos(); break; case 4: mostrarnodo(); break; case 5: buscarnumero(); break; case 6: eliminarnodoinicio(); break; case 7: eliminarnodofinal(); break; case 8: eliminarentredosnodos(); break; case 9: exit(0);break; default: printf("Opcion no valida");break; } }while(opc!=9); getch(); } void eliminarentredosnodos() { q=cab; int h=1; if (cab=NULL) printf("La lista esta vacia"); else { printf("Ingrese Nodo a eliminar: "); scanf("%d",&x); while (q->numero!=x && h==1) { if (q->psig!=NULL) { p=q; q=q->psig; } else h=0; } if (p->psig==NULL) printf("Elemento no Encontardo"); else { if (cab=q) cab=q->psig; else p->psig=q->psig; } delete(q); } getch(); system("CLS"); } void eliminarnodofinal() { p=cab; if (cab==NULL) printf("No hay Numeros en la lista"); if (cab->psig==NULL) { delete (cab); cab=NULL; } else { while(p->psig!=NULL) { aux=p; p=p->psig; } aux->psig=NULL; delete p; numerodenodos--; } getch(); system("cls"); } void eliminarnodoinicio() { if (cab==NULL) printf("No hay numeros que eliminar"); else { aux=cab; cab=cab->psig; delete (aux); aux=NULL; numerodenodos--; } getch(); system("cls"); } void buscarnumero() { int eli; if (cab==NULL) { printf("No hay numeros en la lista"); } else { q=cab; printf("Que Numero desea buscar: "); scanf("%d",&x); pos=1; while(q!=NULL && q->numero!=x) { q=q->psig; pos++; } if (q!=NULL) printf("%d Esta en la lista y en la posicion %d\n",x,pos); else { printf("%d No esta en la lista\n",x); } } getch(); system("cls"); } void insertarnodoinicio(){ n=(dato*)malloc(sizeof (struct dato)); printf("\nElementos a insertar: "); scanf("%d",&x); n->numero=x; n->psig=NULL; if(cab==NULL) cab=n; else{ n->psig=cab; cab=n; } numerodenodos++; system("CLS"); } void mostrarnodo() { if(cab==NULL) printf("Lista vacia.........\n"); else{ p=cab; printf("\nLista de numeros...\n"); while(p!=NULL){ printf("\n%d\n",p->numero); p=p->psig; } printf("\nEl numero de nodos es: %d ",numerodenodos); } getch(); system("CLS"); } void insertarnodoalfinal() { n= (dato*)malloc(sizeof(dato)); printf("Ingresa dato: "); scanf("%d",&x); n->numero=x; n->psig=NULL; if(cab==NULL){ cab=n; numerodenodos++; } else{ p=cab; while(p->psig!=NULL) { p=p->psig; } p->psig=n; numerodenodos++; } getch(); system("CLS"); } void insertarentrenodos() { if(cab==NULL) printf("No hay elementos"); else { printf("Ingrese la posicion en que desees insertar: "); scanf("%d",&pos); if(pos> numerodenodos || pos==1) printf("Solamente es valido entre 2 nodos"); else { n=(dato*)malloc(sizeof(dato)); printf("Ingresa dato: "); scanf("%d",&x); n->numero=x; n->psig=NULL; aux=cab; for(int i=1; i<pos-1; i++) { aux=aux->psig; } n->psig=aux->psig; aux->psig=n; numerodenodos++; } } getch(); system("cls"); } tengo este programa pero tengo un error cuando intento compilar con gcc me marca lo siguiente alguien ayuda ListasSimples.c:16:3: error: unknown type name ‘dato’ dato *psig; ^ ListasSimples.c:20:7: error: unknown type name ‘dato’ dato *cab=NULL; ^ ListasSimples.c:21:7: error: unknown type name ‘dato’ dato *n=NULL; ^ ListasSimples.c:22:7: error: unknown type name ‘dato’ dato *aux=NULL; ^ ListasSimples.c:23:7: error: unknown type name ‘dato’ dato *p=NULL; ^ ListasSimples.c:24:7: error: unknown type name ‘dato’ dato *q; ^ ListasSimples.c:27:7: warning: return type defaults to ‘int’ [-Wimplicit-int] main() ^ ListasSimples.c: In function ‘main’: ListasSimples.c:84:37: warning: implicit declaration of function ‘getch’ [-Wimplicit-function-declaration] getch(); ^ ListasSimples.c: In function ‘eliminarentredosnodos’: ListasSimples.c:104:22: error: request for member ‘numero’ in something not a structure or union while (q->numero!=x && h==1) ^ ListasSimples.c:106:19: error: request for member ‘psig’ in something not a structure or union if (q->psig!=NULL) ^ ListasSimples.c:109:35: error: request for member ‘psig’ in something not a structure or union q=q->psig; ^ ListasSimples.c:115:24: error: request for member ‘psig’ in something not a structure or union if (p->psig==NULL) ^ ListasSimples.c:120:28: error: request for member ‘psig’ in something not a structure or union cab=q->psig; ^ ListasSimples.c:122:24: error: request for member ‘psig’ in something not a structure or union p->psig=q->psig; ^ ListasSimples.c:122:32: error: request for member ‘psig’ in something not a structure or union p->psig=q->psig; ^ ListasSimples.c:125:19: warning: implicit declaration of function ‘delete’ [-Wimplicit-function-declaration] delete(q); ^ ListasSimples.c: In function ‘eliminarnodofinal’: ListasSimples.c:140:12: error: request for member ‘psig’ in something not a structure or union if (cab->psig==NULL) ^ ListasSimples.c:149:12: error: request for member ‘psig’ in something not a structure or union while(p->psig!=NULL) ^ ListasSimples.c:152:8: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c:154:8: error: request for member ‘psig’ in something not a structure or union aux->psig=NULL; ^ ListasSimples.c:155:5: error: unknown type name ‘delete’ delete p; ^ ListasSimples.c: In function ‘eliminarnodoinicio’: ListasSimples.c:176:17: error: request for member ‘psig’ in something not a structure or union cab=cab->psig; ^ ListasSimples.c: In function ‘buscarnumero’: ListasSimples.c:200:24: error: request for member ‘numero’ in something not a structure or union while(q!=NULL && q->numero!=x) ^ ListasSimples.c:202:9: error: request for member ‘psig’ in something not a structure or union q=q->psig; ^ ListasSimples.c: In function ‘insertarnodoinicio’: ListasSimples.c:223:5: error: ‘dato’ undeclared (first use in this function) n=(dato*)malloc(sizeof (struct dato)); ^ ListasSimples.c:223:5: note: each undeclared identifier is reported only once for each function it appears in ListasSimples.c:223:10: error: expected expression before ‘)’ token n=(dato*)malloc(sizeof (struct dato)); ^ ListasSimples.c:226:3: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:227:3: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:232:3: error: request for member ‘psig’ in something not a structure or union n->psig=cab; ^ ListasSimples.c: In function ‘mostrarnodo’: ListasSimples.c:250:19: error: request for member ‘numero’ in something not a structure or union printf("\n%d\n",p->numero); ^ ListasSimples.c:251:5: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c: In function ‘insertarnodoalfinal’: ListasSimples.c:263:6: error: ‘dato’ undeclared (first use in this function) n= (dato*)malloc(sizeof(dato)); ^ ListasSimples.c:263:11: error: expected expression before ‘)’ token n= (dato*)malloc(sizeof(dato)); ^ ListasSimples.c:266:3: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:267:3: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:274:9: error: request for member ‘psig’ in something not a structure or union while(p->psig!=NULL) ^ ListasSimples.c:276:5: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c:278:3: error: request for member ‘psig’ in something not a structure or union p->psig=n; ^ ListasSimples.c: In function ‘insertarentrenodos’: ListasSimples.c:301:21: error: ‘dato’ undeclared (first use in this function) n=(dato*)malloc(sizeof(dato)); ^ ListasSimples.c:301:26: error: expected expression before ‘)’ token n=(dato*)malloc(sizeof(dato)); ^ ListasSimples.c:304:19: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:305:19: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:310:25: error: request for member ‘psig’ in something not a structure or union aux=aux->psig; ^ ListasSimples.c:312:19: error: request for member ‘psig’ in something not a structure or union n->psig=aux->psig; ^ ListasSimples.c:312:29: error: request for member ‘psig’ in something not a structure or union n->psig=aux->psig; ^ ListasSimples.c:313:21: error: request for member ‘psig’ in something not a structure or union aux->psig=n; Título: Re: problema con manejo de nodos en linux Publicado por: furciorifa en 11 Febrero 2016, 03:54 am Código
corrije eso por Código
Título: Re: problema con manejo de nodos en linux Publicado por: abaadoon en 12 Febrero 2016, 04:19 am ya encontre el error lo deje de esta manera; donde puedo darte puntos?
typedef struct datos_alumnos{ char numControl[30]; char nombre[30]; float calificacion; struct datos_alumnos *next; }DATOS; |