开发者

shared buffer processes

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 par开发者_如何转开发t 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);
    }
 }


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.


q_add(1, &n);?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜