我在我的代碼有問題的過程代碼:隊列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