0
我試圖調用將某些字符添加到緩衝區的函數,然後再刪除它們。但我仍然沒有正確地調用這個函數。我正在研究Linux。共享緩衝區進程
ERROR: q_add makes an integer without a cast.
這是部分代碼:
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;
//------------------------------------------------------------------
在適當的文件中的q_add()
定義是:
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;
}
}
而這個功能並未真正發揮作用;如果我取消了出口,我得到一個錯誤:
void q_delete()
{
if (-1 == shmctl(shmid, IPC_RMID, 0))
{
perror("Can't remove shared mem");
//exit(1);
}
}
我試過了,在執行並輸入值 – 2010-08-18 08:24:20
之後,它返回了一個分段錯誤。您從不設置任何有效的值。這可能就是爲什麼它是殘疾人。 – JeremyP 2010-08-18 08:44:41
看着你的代碼,使用'q_add(1,&n);',因爲你只有一個字符 – JeremyP 2010-08-18 08:46:30