Thread: basics of array passing and string parsing

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    Angry basics of array passing and string parsing

    I need to program a simple language generator from user input in BNF. I have never programmed in c before.

    I am having problems dealing with multi-d array passing. From what I've read C passes the pointer to the array, but no matter what I do I keep getting an illegal type error when I first try to reference. The book I bought is real basic.

    One other question is there an easy way to deal with strings other than as an array of char?

    Below is the section of code giving me problems :


    void processinput(char therules[][])
    {
    int x;
    int y;
    int count;
    char temp[25];
    for(x=0;x<numrul;++x)
    {
    y=0;
    while(therules[x][y]==' ')<-this is where throws error
    y=y+1;
    if(therules[x][y]=='<')
    {
    ++y;


    count=0;
    while(therules[x][y]!='>' & y< strlen(therules[x]))
    {
    temp[count]=therules[x][y];
    ++count;
    ++y;
    }}}
    }

  2. #2
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    Just a couple of things:
    Code:
    void processinput(char therules[][])
    You can't pass a two dimensional array to a function without declaring its size like so..

    If it was initially declared as :
    char therules[2][4]

    the you would call processinput like such:
    void processinput(char therules[][4])

    You could do this:
    void processinput(char therules[2][4])

    which is clearer but the 2 is ignored anyway.
    Code:
    while(therules[x][y]!='>' & y< strlen(therules[x]))
    I am assuming you are trying to evaluate while (leftstatement and rightstatement)..
    You should have:
    Code:
    while( therules[x][y] != '>' && y < strlen(therules[x]) )
    && = logical and
    & = address operator or bitwise and
    Last edited by foniks munkee; 03-01-2002 at 07:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing a string array to a function using pointers
    By asofaihp in forum C++ Programming
    Replies: 2
    Last Post: 04-13-2009, 11:31 AM
  2. Passing an array into a function
    By Ryston in forum C++ Programming
    Replies: 4
    Last Post: 08-29-2006, 05:20 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. HELLLLP!!!! string parsing C++ only
    By waki in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2001, 09:41 PM