Hi,

sorry if i write a droll question, i´m realy new to this....
I have written a short testprogram which is reading from a messageQ.
The code is written in C.
If i get a message the printf with the much ***** is comming ok but afterwards 
the program chrashes...
What is the problem with my code? Can somebody help me?

Patrick




#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Multiline_Output.H>
#include <FL/Fl_Button.H>

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <time.h>
#include <unistd.h>
#include <string.h>

struct my_msgbuf
        {
        int mtype;
        int mtext;
        char message[50];
        };

/* Hauptfenster */
Fl_Window *window;

/* Mehrzeiliger output */
Fl_Multiline_Output *output;

/* Button */
Fl_Button *button;
Fl_Button *button2;



void readmessage(Fl_Widget *,void *)
        {
        struct my_msgbuf buf;
        int msqid;
        key_t key;
        key = 67890;
        int counter = 0;
        char text[100];

        if ((msqid = msgget(key, 0644 | IPC_CREAT)) == -1)
                {
                perror("msgget");
                exit(1);
                }

        printf("msqid = %i\n", msqid);

        if (msgrcv(msqid, (struct msgbuf *)&buf, sizeof(buf), 0, 0) == -1)
                {
                perror("msgrcv");
                }
        else
                {
                counter++;
                
printf("********************************************************************\n");
                printf("%05i Receive: mtype: %i, mtext: %i, message: 
%s\n",counter, buf.mtype, buf.mtext, buf.message);
                
printf("********************************************************************\n");

        //      sprintf(text, "%05i Receive: mtype: %i, mtext: %i, message: 
%s\n",counter, buf.mtype, buf.mtext, buf.message);
        //      output->value(text);
                }
        }


void cb_hallo(Fl_Widget *,void *)
        {
        output->value("Hallo");
        }

int main(int argc, char **argv)
        {
        window = new Fl_Window(400,400);

        button = new Fl_Button(100, 50, 200, 50, "MessageQ");
        button->callback(readmessage);

        button2 = new Fl_Button(100, 120, 200, 50, "Hallo");
        button2->callback(cb_hallo);

        output = new Fl_Multiline_Output(100,200,200,100,"Textoutput");
        output->align(FL_ALIGN_BOTTOM);

        window->show(argc,argv);
        return Fl::run();
        }

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to