SoloCodigo
		Programación General => C/C++ => Mensaje iniciado por: danime en Lunes  4 de Diciembre de 2006, 01:10
		
			
			- 
				hola a todos
 queria saber si me podian ayudar con este programa
 se supone que debe recorrer el tablero de ajedres de dimension n desde la posicion f, c
 
 este problema es muy conocido pero me pidieron que lo hiciera con stack
 ademas debe mostrar el tiempo
 
 me da un error que no entiendo
 
 pointer to structure require on left of ->or ->*
 
 
 
 #include<stdlib.h>
 #include<stdio.h>
 #include"time.h"
 
 
 typedef struct {
 int fila, columna, ganador, cuantos;
 float tiempo;
 int opciones[8];}nodo;
 
 typedef struct {
 int tope, cuantos;
 nodo *pila; }stack;
 
 typedef struct{
 int ** matriz; }mat;
 
 
 typedef struct{
 int mov[8][2]; } coordenadas;
 
 typedef struct{
 int cuantos,i,j;
 int opciones[7];}movpos;
 
 
 void init_stack( stack *a, int n)
 {
 int i,j;
 a->tope=-1;
 a->pila=calloc(n*n,sizeof(nodo));
 
 }
 
 void push(stack*s,movpos q,coordenadas a, mat ** B)
 {
 int k;
 
 s->tope=s->tope+1;
 s->pila[s->tope]->fila = (s->pila[s->tope-1]->fila+ a->mov[q.j-1][0]);
 s->pila[s->tope]->columna =(s->pila[s->tope-1]->columna + a->mov[q.j-1][1]);
 s->pila[s->tope]->ganador=q.j;
 s->pila[s->tope]->cuantos=q.cuantos-1;
 
 for(k=0;k<8;k++)
 {
 int l=0;
 
 if(k==q.i)
 k++;
 else
 { s->pila[s->tope]->opciones[l]=q.opciones[k];
 l++;
 }
 s->cuantos++; }
 b->matriz[s->pila[s->tope]->fila+1][s->pila[s->tope]->columna+1]=1;
 }
 
 
 void pop(stack*s,movpos*q, mat ** b, coordenadas a)
 {
 int k;
 movpos *p;
 
 b->matriz[s->pila[s->tope]->fila+1][s->pila[s->tope]->columna+1]=0;
 s->tope=s->tope-1;
 
 opc(s->pila[s->tope]->fila,s->pila[s->tope]->columna, &q, a, &&b)
 
 p->cuantos=q->cuantos-1;
 
 p->i=p->j=0;
 
 for( k=0;k<8;k++)
 {  int l=0;
 
 if(k==s->pila[s->tope]->ganador)
 k++;
 else
 { p->opciones[l]=q->opciones[k];
 l++;
 }
 }
 q =p;
 }
 
 void opc (int f, int c, movpos *pos, coordenadas a, mat ** b )
 {
 int i,j=0;
 for(i=0; i<8; i++)
 {
 if(ocupado((f+a.mov[0]),(c+a.mov[1]), &&b)== 0)
 {
 pos->opciones[j]=i+1;
 j++;
 pos->cuantos++;}
 }
 }
 
 
 int ocupado(int f, int c, mat ** B)
 {
 if(b->matriz[f+1][c+1]==1)
 return (1);
 
 if(b->matriz[f+1][c+1]==0)
 return (0);
 }
 
 
 int verifica(int n, int f, int c, int o)
 {
 
 if(f>n||f<1||c>n||c<1)
 printf("ingresar coordenadas validas");
 return 0;
 
 if(o!='V'||o!='S')
 printf("ingresar opcion valida")
 return 0;
 if(n<5)
 printf("ingresar n > 4")
 return 0;
 
 else
 return 1;
 )
 
 
 
 void init_matriz( mat ** B)
 {
 b->matriz= calloc(n+4, sizeof(int *));
 for(i=0; i<f; i++)
 b->matriz=calloc((n+a, sizeof(int));
 for(int i=0; i<n+4;  i++)
 b->matriz[0]= b->matriz[1]= b->matriz[0]= b->matriz[1]= b->matriz[n+2]= b->matriz[n+3]= b->matriz[n+3]= b->matriz[n+2]=1;
 
 }
 
 
 
 void main(int n, int f, int c, int o)
 {
 
 
 
 if(verifica(n,f,c,o)==1)
 {
 stack *a;
 init_stack(&a,n);
 
 for(i=0; i<(n*n); i++)
 { for(j=0; j<8; j++)
 a->pila->opciones[j]= 0;}
 
 coordenadas * movimientos
 
 movimientos->mov[0][0]= movimientos->mov[7][0]= movimientos->mov[5][1]= movimientos->mov[6][1]= -2;
 movimientos->mov[1][0]= movimientos->mov[6][0]=  movimientos->mov[4][1]= movimientos->mov[7][1]= -1;
 movimientos->mov[2][0]= movimientos->mov[5][0]= movimientos->mov[0][1]= movimientos->mov[5][1] =1;
 movimientos->mov[1][1]= movimientos->mov[2][1]= movimientos->mov[3][0]= movimientos->mov[4][0]= 2;
 
 
 mat tablero;
 init_matriz(&&tablero);
 
 movpos *q
 q->cuantos=q->i=q->j=0;
 int i;
 for(i=0; i<7; i++)
 q->opciones=0;
 
 
 time_586 tstart, tend;
 double Etime, Esec,ttotal=0;
 
 a->tope=a->tope+1;
 a->pila[a->tope]->ganador=0;
 a->pila[a->tope]->cuantos=0;
 a->pila[a->tope]->fila=f;
 a->pila[a->tope]->columna=c;
 a->pila[a->tope]->tiempo=0;
 a->cuantos++;
 tablero->matriz[f+1][c+1]=1;
 
 
 do{
 time(tstart);
 opc(a.pila[a.tope].fila, a.pila[a.tope].columna, &q, movimientos)
 
 if(q->cuantos==0)
 {
 while(q->cuantos==0)
 pop(&a, &q, &&tablero, movimientos);
 
 q->i=rand()%q.cuantos;
 q->j=q.opciones[q->i];
 
 push(&a, q, movimientos, &&tablero )
 time(tend);
 Etime = time_diff(tend,tstart);
 Esec = Etime / 1000000;
 ttotal=ttotal+Esec;
 a->pila[a->tope]->tiempo=ttotal;
 }
 else
 {
 if(q->cuantos==1)
 q->opciones
 if(q->cuantos>1)
 {
 srand(time(NULL));
 q->i=rand()%q->cuantos;
 q->j=q->opciones[q->i]; }
 
 push(&a, q, movimientos, &&tablero)
 time(tend);
 Etime = time_diff(tend,tstart);
 Esec = Etime / 1000000;
 ttotal=ttotal+Esec;
 a->pila[a->tope]->tiempo=ttotal; }while(a.cuantos==n*n);
 
 if(o==S)
 printf("%f",Esec);
 if(o==V)
 {
 stack b
 init_stack(&b,n);
 int j=0;
 for(int i=(n*n)-1;i>-1;i--)
 { a.pila.fila=b->pila[j]->fila;
 a.pila.columna=b->pila[j]->columna;
 a.pila.ganador=b->pila[j]->ganador;
 a.pila.cuantos=b->pila[j]->cuantos;
 a.pila.tiempo=b->pila[j]->tiempo;
 for(int k=0;k<8;k++)
 { a.pila.opciones[k]=b->pila[j]->opciones[k];
 j++ }   }
 for(int i=(n*n)-1;i>-1;i--)
 { printf("%f %d %d %\n",b->pila->tiempo,b->pila->ganador,b->pila->fila,b->pila->columna;)
 }
 }
 
 
 }
 
 }
 
 
 
 
 el erro me sale en casi todas las lineas donde ocupo ->
 
 ayudenme porfavor!!!
- 
				en luga de usar ->, usa punto (.)
 
 como por ejemplo
 no corri el programa, pero creo que con eso se arregla.