tags:

views:

63

answers:

2

I am trying to call functions that are add some characters to the buffer and then remove them after. but am still failing to call the function properly. I am working on Linux.

ERROR: q_add makes an integer without a cast.

This is part of the code:

do {
    printf("Enter shared buffer operation ");
    printf("i(init)/a(add)/r(remove)/t(items)/d(delete)");
    scanf("%c%c", &op, &discard);
    int a=1;
    char n;

    switch ( op )
    {
      case 'i':
               printf("Enter nnumber a leter here!");
               scanf("%c" &n)
               q_add(a, &n);
               break;

      case 'a':
               q_delete();
               break;

      case 'r':
               q_remove(a, &n);
               break;
       //------------------------------------------------------------------

The definition of q_add() in the appropriate file is:

 void q_add(int n, char *x)
 {
    shbuf->count += n;
    while ( n-- > 0 )
    {
        shbuf->buf[shbuf->inspos++] = *x++;
        if ( shbuf->inspos ==  QSIZ )
            shbuf->inspos = 0;
    }
 }

And this function doesn't really work; if I uncomment the exit, I get an error:

 void q_delete()
 {
    if ( -1 == shmctl(shmid, IPC_RMID, 0) )
    {
        perror("Can't remove shared mem");
        //exit(1);
    }
 }
+4  A: 

You are calling the function as:

int a; 
char n;
....
q_add(a, n);

but the def is:

void q_add(int n, char *x)

It expects a char * as the 2nd argument and you are sending a char.

codaddict
+3  A: 

q_add(1, &n);?

Andreas Brinck
I tried this, and it returned a segmentation error, after executing and entering the value
George William Mugume
You never set a to anything valid. That's probably why it's segfaulting.
JeremyP
Looking at your code, use `q_add(1, ` because you only have one char
JeremyP
@JeremyP thanks for the catch
Andreas Brinck
tried that! however after entering the character, it doesnt switch to the next function.just keeps bring "printf("i(init)/a(add)/r(remove)/t(items)/d(delete)"); "
George William Mugume