Thread: keep getting a parse error

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    26

    keep getting a parse error

    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);

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    change
    Code:
    #define BSIZE 512;
    to
    Code:
    #define BSIZE 512
    Regards,

    Dave

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    @ v3dant :

    I am a newbie , want to ask some silly question:
    int pipe1[2];
    int pipe2[2];
    pipe(pipe1);
    pipe(pipe2);
    what's mean 'pipe' , how to work?

    int pid = fork();
    fork() function ?

    read(pipe1[0], buf, BSIZE);
    Why I have read some c++ books, but donn't meet those function: fork() and read()?

    Please give some guide about c++ book,
    thanks.

  4. #4
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    pipe ( ) opens array first element for reading and array second element for writing.
    this array is used to communicate between two processes. ie. parent and child process.

    fork ( ) is used to create child process.

    read ( ) can be used to read from pipe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM