summaryrefslogtreecommitdiff
path: root/lab08/snd.c
blob: 0b8fbd69795c80a68c5ba8044d432e4d0ffceb01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "stdio.h"
#include "stdlib.h"
#include "mqueue.h" /* this header file is required */
#include "sys/stat.h"
#include "string.h"
#include "time.h"

#define MAX_CHAR 127
#define STR_SIZE 100

void give_string(char *);

int main (void)
{
	int status = 0;
	/* declare a message queue variable */

	char *sent_msg;
	struct mq_attr attr;
	
	/* open the message queue for writing.  don't forget to check the return value */
	
	sent_msg = (char *) malloc (100);
	if (NULL == sent_msg)
	{
		perror("malloc");
		exit(1);
	}
	
	/* give_string(sent_msg); this function generates a random string */
	/* you can use this or just send your own string */
	
	/* get the message queue attribute structure */

	/* send a message */
	
	free(sent_msg);
	
	status = mq_close(analyze_q);
	
	return(0);
}


void give_string(char *result)
{
	int j = 0;
	int i = 0;

	srand((unsigned)time(NULL));
	
	for (i=0;i<100;i++)
	{
		result[i] = (char) (1 + (int) (MAX_CHAR * (rand() / (RAND_MAX + 1.0))) );
	}
	
}