Help with C program debug
Hi folks:
Im trying to debug an error in my program and would like anyones help with it.
the problem is in the openpipe routine. Here I have set up a 2D array of 'datastruct' called bigstruct and later on am trying to write values into particular elements of bigstruct.
I am seeing this error :
openpipe.c:44: error: expected expression before ‘.’ token
openpipe.c:48: error: expected expression before ‘.’ token
openpipe.c:49: error: expected expression before ‘.’ token
#include <stdio.h>
// Description: Basically this syscall fills the pipe descriptor data structure pd.
//It does so only if the process has not already created OPEN_MAX number of pipes
#define PIPE_BUF 256
#define OPEN_MAX 5 //max no of pipes for a single process
#define MAX_PROC 8 //max number of processes running at a given time
typedef struct pipedesc {
int owner_pid; // process id of the pipe owner
int key; // unique key that identifies pipes within the process
} pipedesc;
typedef struct datastruct{
int pid; //process id of pipe owner
char buf_ptr[PIPE_BUF];
int state ;
} bigstruct[MAX_PROC][OPEN_MAX]; //declaring a 2D array
int pid[MAX_PROC];
int openpipe (pipedesc *pd)
{
int row, column;
int i,j;
int curr_pid = (int)getpid();
for (i=0;i<MAX_PROC;i++)
{
if (curr_pid == pid[i])
{
printf("Found an entry in big struct with same pid\n");
row = i;
for(j=0;j<OPEN_MAX;j++)
{
if( (bigstruct[i][j]).state == 0) //*****openpipe.c:44: error: expected expression before ‘.’ token
{
printf("Found a cell in big struct with state off\n");
//Store current process in bigstruct
bigstruct[i][j].state = 1; //******openpipe.c:44: error: expected expression before ‘.’ token
bigstruct[i][j].pid = curr_pid; //******openpipe.c:44: error: expected expression before ‘.’ token
//fill the filedescriptor pd with info about this cell
pd->owner_pid = curr_pid;
pd->key = j;
return 1;
}
}
printf("Maximum number of processes have already been allocated\n");
return 0;
}
}
printf("Max number of process has been reached\n");
}
The main function where I call this is as follows :
#include <stdio.h>
#include "openpipe.c"
int main() {
pipedesc p1,p2,p3,p4,p5;
openpipe(p1);
}
Any suggestions?