할당

2011-10-17 2 views
0

여기에 다음과 같은 문제입니다, 다음 코드에서 호환되지 않는 포인터 유형에서 Asisgnment을 받고 임 :할당

aux->sig=nodo; 

행 60 : 다음과 같이

는 라인 (43)가가는 당신이를 다시 시작하려면 :

aux2=aux2->sig; 

는 기본적으로 "AUX2"

의 모든 오류가 메신저무슨 일이 벌어지는거야? 그리고 당신이 저에게 설명 할 수 있다면, Im 학생과 Im은 프로그래밍에 기본적으로 새로운 것입니다.

proyecto2mod.c: In function ‘agrega_nombre’: 
proyecto2mod.c:43: warning: assignment from incompatible pointer type 
proyecto2mod.c:60: warning: assignment from incompatible pointer type 
proyecto2mod.c: In function ‘busca_cliente’: 
proyecto2mod.c:105: warning: assignment from incompatible pointer type 
proyecto2mod.c: In function ‘ordena’: 
proyecto2mod.c:118: warning: assignment from incompatible pointer type 
proyecto2mod.c:119: error: request for member ‘nombre’ in something not a structure or union 
proyecto2mod.c:119: error: request for member ‘nombre’ in something not a structure or union 
proyecto2mod.c:120: error: request for member ‘direccion’ in something not a structure or union 
proyecto2mod.c:120: error: request for member ‘direccion’ in something not a structure or union 
proyecto2mod.c:121: error: request for member ‘num_cliente’ in something not a structure or union 
proyecto2mod.c:122: error: request for member ‘ant’ in something not a structure or union 

... 등등. Heres는

코드 :

주요 CODE

#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include "clientes.h" 
#include "ventas.h" 
extern void agrega_nombre(ApLista1 inicio, ApLista1 aux,ApLista1 nodo, ApLista1 aux2); 
extern void busca_cliente(ApLista1 inicio, ApLista1 aux,ApLista1 nodo, ApLista1 aux2, ApLista2 inicioventas, ApLista2 auxventas, ApLista2 nodoventas, ApLista2 aux2ventas); 
extern int ordena(ApLista1 inicio, ApLista1 aux,ApLista1 nodo,ApLista1 *aux2); 
int main(void) 
{ 
int menu=0; 

//LISTA1 *aux2,*nodo; 
ApLista1 inicio, aux, nodo, aux2; 
ApLista2 inicioventas, auxventas,nodoventas,aux2ventas; 

inicio=NULL; 
nodo=malloc(sizeof(LISTA1)); 
aux=malloc(sizeof(LISTA1)); 
inicioventas=NULL; 
nodoventas=malloc(sizeof(LISTA2)); 
auxventas=malloc(sizeof(LISTA2)); 

system("clear"); 
while(menu!='6') 
{ 
    //funcion void carga_datos(); 
    printf("TIENDA DEPARTAMENTAL\n\n\n"); 
    printf("1. Agregar a un Cliente.\n2. Agregar una venta.\n3. Buscar Cliente. \n4.  Borrar Cliente. \n5. Borrar una venta. \n6. Salir."); 
    printf("\n\nElige una opcion: "); 
    scanf("%d", &menu); 
    switch(menu) 
{ 
case 1: 
    system("clear"); 
    printf("opcion1\n"); 

    agrega_nombre(inicio, aux,nodo, aux2); 
    menu=0; 
    break; 
case 2: 
    system("clear"); 
    printf("opcion2\n"); 

    ///lo mismo que agrega_cliente pero utilizando la lista de ventas. 
    menu=0; 
    break; 
case 3: 
    system("clear"); 
    printf("opcion3\n"); 
    busca_cliente(inicio,aux,nodo,aux2,inicioventas, auxventas, nodoventas, aux2ventas); 
    menu=0; 
    break; 
case 4: 
    system("clear"); 
    printf("opcion4\n"); 
    //borra_cliente(inicio,aux,nodo,aux2,inicioventas, auxventas, nodoventas, aux2ventas); 
    menu=0; 
    break;// 
case 5: 
    system("clear"); 
    printf("opcion5\n"); 
    //Lo Mismo que borra cliente pero en la lista de ventas solamente. 
    menu=0; 
    break; 
case 6: 
    system("clear"); 
    printf("Adios!\n"); 
    exit(1); 
    menu=0; 
    break; 
} 
    } 
} 

주에 이동 기능 :

void agrega_nombre(ApLista1 *inicio, ApLista1 aux,ApLista1 nodo, ApLista1 aux2) 
{ 

FILE *clientes; 
int pops=0, sanders=0; 
char aux_char[80]; 


    system("clear"); 
clientes=fopen("clientes.txt", "a+"); 
//fseek(clientes, 0L, SEEK_END); 



if(nodo==NULL) 
{ 
    printf("No hay memoria\n"); 
    exit(1); 
} 
    printf("NOMBRE:"); 
    scanf("%s", nodo->nombre); 
    printf("DIRECCION:"); 
    scanf("%s",nodo->direccion); 
    printf("NUMERO DE CLIENTE:"); 
    scanf("%d", &nodo->num_cliente); 

    if(inicio==NULL) 
{ 
    (*inicio)=nodo; 
    (*inicio)->sig=NULL; 
    (*inicio)->ant=NULL; 
    aux=(*inicio); 
} 
    else 
{ 
    aux->sig=nodo; 
    nodo->ant=aux; 
    aux=nodo; 
    nodo->sig=NULL; 
} 

    pops++; 

    aux2=(*inicio); 

    while(aux2!=NULL) 
{ 
    fprintf(clientes, "%s\n", aux2->nombre); 
    fprintf(clientes, "%s\n", aux2->direccion); 
    fprintf(clientes, "%d\n", aux2->num_cliente); 
    puts(aux2->nombre); 
    puts(aux2->direccion); 
    aux2=aux2->sig; 
} 


    aux2=aux; 
    do 
{ 
    puts(aux2->nombre); 
    aux2=aux2->ant; 
} 
    while(aux2!=NULL); 
    fclose(clientes); 
} 

//Funcion Busqueda 
void busca_cliente(ApLista1 inicio, ApLista1 aux,ApLista1 nodo, ApLista1 aux2, ApLista2 inicioventas, ApLista2 auxventas, ApLista2 nodoventas, ApLista2 aux2ventas) 
    { 
char nombrebusqueda[80]; 
int numclienteprueba; 
inicio=NULL; 

printf("Dame el nombre del cliente a buscar\n"); 
scanf("%s",nombrebusqueda); 
aux2=aux; 
while(aux2!=NULL) 
    { 
    printf("Entramos al While Aux2"); 
    if((strcmp(nombrebusqueda,aux2->nombre))==0) 
     { 
    printf("Encontramos BAM"); 
    puts(aux2->nombre); 
    ////////Buscamos la venta 
    aux2ventas=auxventas; 
    while(aux2ventas!=NULL) 
     { 
     numclienteprueba=aux2ventas->num_clienteventas; 
     if(numclienteprueba==aux2ventas->num_clienteventas) 
      { 
     printf("Wow"); 
     ///Aqui ensenamos las ventas que ha tenido el cliente y la i informacion de la estructura. 
      } 
     aux2ventas=aux2ventas->sigvent; 
     } 
    //////////// 
     } 
    aux2=aux2->sig; 
    } 
    } 

//Funcion Ordena 



    int ordena(ApLista1 inicio, ApLista1 aux,ApLista1 nodo,ApLista1 *aux2) 
{ 
char pruebaman[80],probaman[80];//nombres 
char pruebadireccion[150],probadireccion[150];//direccion 
int pruebanum_cliente,probanum_cliente;//numero de cliente 
aux2=aux; 
strcpy(pruebaman,aux2->nombre); 
strcpy(pruebadireccion,aux2->direccion); 
pruebanum_cliente=aux2->num_cliente; 
aux2=aux2->ant; 

do 
    { 

    strcpy(probaman,aux2->nombre); 

    if(pruebaman[0]<probaman[0]) 
{ 
    strcpy(pruebaman,aux2->nombre); 
    strcpy(pruebadireccion,aux2->direccion); 
    pruebanum_cliente=aux2->num_cliente; 
    aux2=aux2->sig; 
    strcpy(aux2->nombre,probaman); 
    strcpy(aux2->direccion,probadireccion); 
    probanum_cliente=aux2->num_cliente;  
} 
    strcpy(pruebaman,aux2->nombre); 
    strcpy(pruebadireccion,aux2->direccion); 
    pruebanum_cliente=aux2->num_cliente; 

    aux2=aux2->ant; 


    printf("Ciclo\n\n"); 

} 
while(aux2!=NULL); 
aux2=aux; 
strcpy(pruebaman,aux2->nombre); 
aux2=aux2->ant; 
strcpy(probaman,aux2->nombre); 
if(pruebaman[0]<probaman[0]) 
ordena(inicio,aux,nodo,aux2); 
} 

구조 :

#include<stdio.h> 
    typedef struct clientes{ 
    char nombre[80]; 
    char direccion[150]; 
    int num_cliente; 
    struct cliente*sig; 
    struct clientes *ant; 
    struct ventas *vent; 
    }LISTA1; 
    typedef struct clientes *ApLista1; 

두 번째 구조 :int ordena()에서 20,973,210

#include<stdio.h> 
    typedef struct ventas{ 
    int num_clienteventas; 
    char nombre_producto[150]; 
    int precio; 
    int unidades; 
    char fecha[11]; 
    struct ventas *sigvent; 
    struct ventas *antvent; 
    }LISTA2; 
    typedef struct ventas *ApLista2; 

답변

4

, 당신은 기본적으로 struct clientes**ApLista1*aux2을 정의합니다. 그런 다음 에 할당하려고 시도합니다.이 번호는 ApLista1 aux, 즉 struct clientes*으로 정의됩니다. 누락 된 별을 메모하십시오.

aux2이 구조체에 대한 포인터에 대한 포인터이므로 aux2->nombre과 같은 호출이 컴파일되지 않는 이유는 분명합니다. 해결책은 aux2ApLista1으로 정의하거나 필요한 경우 참조를 해제하는 것입니다.

오, 그리고 부수적으로 - IMO, *typedef 뒤에 숨기는 것은 좋지 않습니다. 더 적은 정보를 입력하는 데 도움이되지 않으며 코드를 읽기 쉽게 만듭니다.이 경우에는 오류가 발생하기 쉽습니다.

+0

typedef에'*'가 포함되어 있습니다. 그렇게하면 형식이 Microsoft의'lp' 접두사와 같은 포인터이거나 이름의 어딘가에'ptr' 또는'handle'을 사용하지 않는 경우가 종종 있습니다. – tomlogic