Queues with checks and customers

Asked

Viewed 103 times

-1

I want to create a Checkbook Or Pool.. of checks.. as if it were a Queue waiting (FIFO) and I have some difficulties. For now the code I have is giving me some errors.

I’m having such mistakes:

Item.h:16:16: warning: struct has no members [-Wpedantic]
Item.c:22:8: error: ‘struct cheque’ has no member named ‘refc’

Code:

#ifndef _ITEM_
#define _ITEM_ 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

   /* A chave pela qual se arruma os elementos e a refc*/
    #define key (a) (a != NULL ? a->refc : "")  

    #define less (a,b) (strcmp (a,b)<0)
    #define eq(a,b) (strcmp (a,b) == 0)
    #define NULLitem NULL

typedef long int* Key;                  /* Definir a chave, ponteiro */

typedef struct cheque {                 /* Nome da estrutura */
    int valor
    long int refe
    long int refb
    long int* refc
}*Item;     /* O Item vai ser um ponteiro para a estrutura */

Item newItem (int valor, long int refe, long int refb, long int* refc);
void deleteItem (Item a);
void visitItem (Item a);

#endif
  • 3

    Miguel, welcome to Stackoverflow! The way your question is going is that you want us to do your homework for you. In order to help you you should post what you have already tried to do and what is your specific doubt.

  • I already switched to a specific question. Yes I need help with my homework because I don’t know how to do most of it.. And because there are several possible answers I did not know what to do. And yes I am also new in stackoverflow

1 answer

0

I’ve already figured out:

typedef struct cheque {                 /* Nome da estrutura */
    int valor;
    long int refe;
    long int refb;
    long int* refc;


}*Item;                         /* O Item vai ser um ponteiro para a estrutura */

But now I’m having another kind of mistake:

Item. c: In Function 'newItem': Item. c:14:2: Warning: implicit declaration of Function ːstrdup' [-Wimplicit-Function-declaration]

x->refc = strdup(refc); Item. c:14:10: Warning: assignment makes Pointer from integer without a cast [enabled by default] x->refc = strdup(refc);

Item. c: In Function 'visitItem': Item. c:34:2: warning: format ‘%p’ expects argument of type ‘void *, but argument 2 has type ‘long int *’ [-Wformat=] printf("refc: %p\n", a->refc);


    #ifndef _ITEM_
    #define _ITEM_ 

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    #define key (a) (a != NULL ? a->refc : "")      
    #define less (a,b) (strcmp (a,b)<0)
    #define eq(a,b) (strcmp (a,b) == 0)
    #define NULLitem NULL

    typedef long int* Key;                  

    typedef struct cheque {                 
        int valor
        long int refe
        long int refb
        long int* refc

    }*Item;                         

    Item newItem (int valor, long int refe, long int refb, long int* refc);
    void deleteItem (Item a);
    void visitItem (Item a);

    #endif


----------
#include "Item.h"
#include <stdio.h>
#include <stdlib.h>


Item newItem (int valor, long int refe, long int refb, long int refc)
{

    Item x = (Item) malloc (sizeof(struct cheque));

    x->valor = valor;
    x->refe = refe;
    x->refb = refb;
    x->refc = strdup(refc);

    return x;
}


void deleteItem (Item a)
{
    free(a->refc);
    free(a);

}


void visitItem (Item a)
{

    printf("valor: %d\n", a->valor);
    printf("refe: %ld\n", a->refe);
    printf("refb: %ld\n", a->refb);
    printf("refc: %p\n", a->refc);

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.