Thread: Help with C program debug

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    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?

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    You really should use code tags.

    Code:
    #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);
    
    }

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by nikhilbk View Post
    Any suggestions?
    Yea. Read the stickies and learn how to properly post code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 10-18-2009, 02:33 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Plz help me to debug my program
    By Bage in forum Linux Programming
    Replies: 1
    Last Post: 04-02-2004, 01:54 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM