我在我的代码有问题的过程代码:队列Linux无法写
FILE *fp;
int i,
counter; // Liczba liter w wiadomosci
wchar_t buffer[1024], *line;
struct MsgStructure WB; // Write Buffor
setlocale(LC_ALL, "pl_PL.UTF-8");
while(run)
{
fp = fopen(FIFO, "r");
fwide(fp, 1);
while ((line = fgetws(buffer, sizeof buffer/sizeof buffer[0], fp)) != NULL)
{
counter = 0;
for (i = 0; line[i] != L'\0'; i++)
if (iswalpha(line[i]))
counter++;
WB.Msg = counter;
if ((WriteToQueue(qid, &WB)) == -1)
{
perror("Error\n");
}
}
fclose(fp);
}
我的程序从FIFO读取文件再算上字母的金额,然后我想写它来排队,但我得到我不能写排队的错误,因为“错误的参数”
我的结构:
struct MsgStructure {
long int MsgType;
int Msg;
};
WriteToQueue是一个简单的函数:
int WriteToQueue(int qid, struct MsgStructure *qbuf){
int result, BufSize;
BufSize = sizeof(struct MsgStructure) - sizeof(long);
result = msgsnd(qid, qbuf, BufSize, 0);
return(result);
}
我的消息类型为int和计数器数据类型为int了。我不知道为什么这不起作用。也许这是setlocale的问题? 队列正在其他进程中创建。
更大的“错误的参数”你的意思是EINVAL(又名无效参数)? – hroptatyr
“无效参数” –
您是否成功使用'msgget()'获得'qid'? – hroptatyr