I have created an array of strings in struct and it is shared.
the struct is as following :
struct data{
int uids[5];
int sockids[5];
int stat[30];
char msgs[30][1024];
};
this is the writing part and i can see the string on printf.
for (int i = 0; i < bufSize; i++) {
if ((*d).stat[i] == -1) {
(*d).stat[i] = sockid;
memset(&((*d).msgs[i][0]), 0, strlen(d->msgs[i]));
strncpy((*d).msgs[i], buf,1023);
printf("\nwriting for me %d %s\n",sockid,d->msgs[i]);
return 1;
}
}
for reading from the same area :
for(int i=0;i<bufSize;i++){
if((*d).stat[i]==mysocket){
(*d).stat[i]=-1;
printf(" message for me %d %d %s\n",mysocket,d->stat[i],d->msgs[i]);
fflush(stdout);
send(mysocket,(*d).msgs[i],strlen((*d).msgs[i]),0);
memset(&((*d).msgs[i][0]), 0, strlen(d->msgs[i]));
}
}
in the reading part i get blank sometimes...
sample output.. :
writing for me 6 36753 : sending some message
message for me 6 -1
sometimes the message comes and sometimes its blank. Can anyone please point out what is the error.