mercury841
25-05-2006, 20:12
Devo fare un programmino che manda un messaggio ad una coda.Ho fatto in questo modo:
#include <sys/types.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
int key,//chiave per aprire la coda
mqid;//id della coda
size_t len;//lunghezza del messaggio
long type;
struct msgbuf *p_mes;//puntatore al messaggio
if ( argc != 4){
printf("Utilizzo: %s <pathname> <type> <message_data>\n",argv[0]);
exit(1);
}
type=atoi(argv[2]);
len=strlen(argv[3]);
//alloco il puntatore al messaggio
if ( ( p_mes=calloc(sizeof(long)+len,sizeof(char)) ) == NULL )
perror("malloc"),exit(1);
//srivo messaggio e tipo
p_mes->mtype=type;
strcpy(p_mes->mtext,argv[3]);
//genero la chiave per aprire la coda
if ((key = ftok(argv[1],1)) == -1){
perror("ftok");
exit(1);
}else{//apro la coda
if ((mqid=msgget(key, S_IRUSR|S_IWUSR|IPC_CREAT)) == -1 ){
perror("msgget");
exit(1);
}
}
if ( msgsnd(mqid,p_mes,len,0) == -1 )
perror("msgsnd"),exit(1);
return(0);
}
Quando vado a compilare mi da questi errore:
msgsend.c:36: error: dereferencing pointer to incomplete type
msgsend.c:37: error: dereferencing pointer to incomplete type
Le linee 36 e 37 sono:
36 p_mes->mtype=type;
37 strcpy(p_mes->mtext,argv[3]);
Qual'è il motivo di questo errore, sapreste aiutarmi?Grazie
#include <sys/types.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
int key,//chiave per aprire la coda
mqid;//id della coda
size_t len;//lunghezza del messaggio
long type;
struct msgbuf *p_mes;//puntatore al messaggio
if ( argc != 4){
printf("Utilizzo: %s <pathname> <type> <message_data>\n",argv[0]);
exit(1);
}
type=atoi(argv[2]);
len=strlen(argv[3]);
//alloco il puntatore al messaggio
if ( ( p_mes=calloc(sizeof(long)+len,sizeof(char)) ) == NULL )
perror("malloc"),exit(1);
//srivo messaggio e tipo
p_mes->mtype=type;
strcpy(p_mes->mtext,argv[3]);
//genero la chiave per aprire la coda
if ((key = ftok(argv[1],1)) == -1){
perror("ftok");
exit(1);
}else{//apro la coda
if ((mqid=msgget(key, S_IRUSR|S_IWUSR|IPC_CREAT)) == -1 ){
perror("msgget");
exit(1);
}
}
if ( msgsnd(mqid,p_mes,len,0) == -1 )
perror("msgsnd"),exit(1);
return(0);
}
Quando vado a compilare mi da questi errore:
msgsend.c:36: error: dereferencing pointer to incomplete type
msgsend.c:37: error: dereferencing pointer to incomplete type
Le linee 36 e 37 sono:
36 p_mes->mtype=type;
37 strcpy(p_mes->mtext,argv[3]);
Qual'è il motivo di questo errore, sapreste aiutarmi?Grazie