簡體   English   中英

來自不兼容指針類型的分配

[英]Assignment from Incompatible Pointer Types

這是以下問題,我在下一個代碼中從不兼容的指針類型獲取Asisgnment:

為了繼續執行此操作,第43行如下:

  aux->sig=nodo;

60行:

 aux2=aux2->sig;

基本上我在“ aux2”中得到了每個錯誤

是什么原因造成的? 如果您能向我解釋一下,我是學生,我基本上是編程新手。

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

... 等等。

繼承人代碼:

主要代碼

#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;

二級結構:

  #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;

int ordena()可以定義aux2作為ApLista1* ,這基本上是一個struct clientes** 然后嘗試將其分配到aux ,它被定義為ApLista1 aux ,即struct clientes* -注意沒有明星。

aux2是指向結構的指針,很明顯為什么不編譯aux2->nombre類的調用。 該解決方案是限定aux2作為ApLista1 ,或在需要時解除引用它。

哦,還有一個要點-IMO,將*隱藏在typedef后面不是一個好習慣。 它並不能幫助您減少鍵入次數,並且會使代碼的可讀性降低-在這種情況下,更容易出錯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM