Задание:
2 приложения отправляют строку на 3 приложение, которое определяет какая строка длинее и выводит повторяющиеся символы строк.
Использовать очередь сообщений.
листинг:
//read
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/msg.h>
#include <string.h>
#include <iostream>
#include <set>
using namespace std;
struct MyStruct
{
long mtype;
char text[80];
};
set<char> *calculation(char *text1, char *text2)
{//text1 < text2
int count1 = strlen(text1);
int count2 = strlen(text2);
set<char> *s = new set<char>;
int j;
for(int i = 0; i < count1; i++)
for(j = 0; j < count2; j++)
if(text1 == text2[j])
s->insert(text1);
return s;
}
int main()
{
set<char> *s;
MyStruct msg1, msg2;
int msgid1, result;
msgid1 = msgget(4000, IPC_CREAT|0666);
msgrcv(msgid1, &msg1, sizeof(MyStruct), 1, 0);
msgrcv(msgid1, &msg2, sizeof(MyStruct), 2, 0);
result = strcmp(msg1.text, msg2.text);
if(!result)
{
cout << "strings are equal" << endl;
return 0;
}
else
{
if(result < 0)
{
cout << msg1.text << " < " << msg2.text << endl;
s = calculation(msg1.text, msg2.text);
}
else
{
{
cout << msg2.text << " < " << msg1.text << endl;
s = calculation(msg2.text, msg1.text);
}
}
for(set<char>::const_iterator it = s->begin(); it != s->end(); it++)
cout << *it << endl;
}
delete s;
return 0;
}
все работает как надо (помоему + лучше пока идей нету с алгоритмом), однако после завершения (return из main) происходит SIGABRT и все в stdout выводится(((
из-за чего?
P.S.
листинг отправляющего
//write1
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/msg.h>
#include <string.h>
#include <iostream>
using namespace std;
struct MyStruct
{
long mtype;
char text[80];
};
int main()
{
MyStruct msg;
int msgid;
msgid = msgget(4000, IPC_EXCL|0666);
cout << "write string" << endl;
cin >> msg.text;
msg.mtype = 1;
msgsnd(msgid, &msg, sizeof(MyStruct), 0);
return 0;
}
//write1
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/msg.h>
#include <string.h>
#include <iostream>
using namespace std;
struct MyStruct
{
long mtype;
char text[80];
};
int main()
{
MyStruct msg;
int msgid;
msgid = msgget(4000, IPC_EXCL|0666);
cout << "write string" << endl;
cin >> msg.text;
msg.mtype = 2;
msgsnd(msgid, &msg, sizeof(MyStruct), 0);
return 0;
}
изменил set<char> на bool[26]. алфавит английский. Но проблему не решил ((