Code:
#include <iostream>
#include <cstring>
#include <ctime>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include "string2int.h"
using namespace std;
#define BSIZE 512;
void parent(int m);
int main()
{
parent(100);
return 0;
}
void parent(int m)
{
int pipe1[2];
int pipe2[2];
pipe(pipe1);
pipe(pipe2);
char buf[80];
int pid = fork();
if(pid < 0)
cout<<"ERROR"<<endl;
else if(pid == 0)
{
read(pipe1[0], buf, BSIZE);
}
else
{
int numMsgs=m;
int msgCount=1;
string pLinStr;
string pMsgStr;
int pRanLines;
int lineTot=0;
char pMsgLine[80];
int x;
int y;
int z;
int a;
srand(time(0));
while(msgCount < numMsgs)
{
pRanLines = (1+ rand() %5);
if(msgCount == 100)
cout<<"bye"<<endl;
//write(pipe1[1],"bye",3);
else
{
y=0;
for(x=0; x<pRanLines; x++)
{
pMsgLine[y] = 'm';
y++;
pMsgStr = BasicTypeToStr(msgCount);
for(z=0; z<pMsgStr.size(); z++)
{
pMsgLine[y]=pMsgStr[z];
y++;
}
pMsgLine[y]=' ';
y++;
pMsgLine[y]='l';
y++;
pMsgLine[y]='i';
y++;
pMsgLine[y]='n';
y++;
pMsgLine[y]='e';
y++;
pMsgLine[y]=' ';
y++;
lineTot++;
pLinStr=BasicTypeToStr(lineTot);
for(z=0; z<pLinStr.size(); z++)
{
pMsgLine[y]=pLinStr[z];
y++;
}
pMsgLine[y]='*';
if(x == pRanLines-1)
pMsgLine[y]='#';
y++;
}
write(pipe1[1],pMsgLine,y);
close(pipe1[1]);
}
msgCount++;
}
}
}
i keep getting the following error: parent.c: In function `void parent(int)':
parent.c:37: error: parse error before `;' token
line 37 is read(pipe1[0], buf, BSIZE);