C parentheses, brackets and brace

Discussion in 'C Programming' started by case.learning@gmail.com, Jun 15, 2007.

  1. Guest

    Hi everyone,

    I'm doing a C problem checking for rudimentary syntax errors like
    unbalanced parentheses, brackets, and braces. I only know parentheses
    () or braces {}, but do not know what brackets [] are for in a C
    program.

    Could you shed some light for me?

    Thanks.

    Mark.
    , Jun 15, 2007
    #1
    1. Advertising

  2. wrote:
    >
    > Hi everyone,
    >
    > I'm doing a C problem checking for rudimentary syntax errors like
    > unbalanced parentheses, brackets, and braces. I only know parentheses
    > () or braces {}, but do not know what brackets [] are for in a C
    > program.
    >
    > Could you shed some light for me?


    Certainly you must have seen arrays used by now if you're working on
    such a project?

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Jun 15, 2007
    #2
    1. Advertising

  3. On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
    wrote:

    >Hi everyone,
    >
    >I'm doing a C problem checking for rudimentary syntax errors like
    >unbalanced parentheses, brackets, and braces. I only know parentheses
    >() or braces {}, but do not know what brackets [] are for in a C
    >program.


    Array indexing.

    char foo[12]; // declares an array of 12 chars
    foo[0] = 'a'; // sets the first element to 'a'
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Jun 15, 2007
    #3
  4. Guest

    On Jun 15, 9:52 am, Mark McIntyre <> wrote:
    > On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
    >
    > wrote:
    > >Hi everyone,

    >
    > >I'm doing a C problem checking for rudimentary syntax errors like
    > >unbalanced parentheses, brackets, and braces. I only know parentheses
    > >() or braces {}, but do not know what brackets [] are for in a C
    > >program.

    >
    > Array indexing.
    >
    > char foo[12]; // declares an array of 12 chars
    > foo[0] = 'a'; // sets the first element to 'a'
    > --
    > Mark McIntyre
    >
    > "Debugging is twice as hard as writing the code in the first place.
    > Therefore, if you write the code as cleverly as possible, you are,
    > by definition, not smart enough to debug it."
    > --Brian Kernighan



    Oh I got it. Thanks very much.

    Mark.
    , Jun 15, 2007
    #4
  5. Guest

    On Jun 15, 10:02 am, wrote:
    > On Jun 15, 9:52 am, Mark McIntyre <> wrote:
    >
    >
    >
    > > On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,

    >
    > > wrote:
    > > >Hi everyone,

    >
    > > >I'm doing a C problem checking for rudimentary syntax errors like
    > > >unbalanced parentheses, brackets, and braces. I only know parentheses
    > > >() or braces {}, but do not know what brackets [] are for in a C
    > > >program.

    >
    > > Array indexing.

    >
    > > char foo[12]; // declares an array of 12 chars
    > > foo[0] = 'a'; // sets the first element to 'a'
    > > --
    > > Mark McIntyre

    >
    > > "Debugging is twice as hard as writing the code in the first place.
    > > Therefore, if you write the code as cleverly as possible, you are,
    > > by definition, not smart enough to debug it."
    > > --Brian Kernighan

    >
    > Oh I got it. Thanks very much.
    >
    > Mark.


    I got another question. How are escape sequences with [ used in a C
    source file?

    Thanks.

    Mark.
    , Jun 15, 2007
    #5
  6. On Fri, 15 Jun 2007 09:24:37 -0700, in comp.lang.c ,
    wrote:

    >I got another question. How are escape sequences with [ used in a C
    >source file?


    I assume you're thinking of ANSI escapes used for changing the colour
    of screen characters etc. These would form part of a string you were
    printing out, so just put them in same as you would in shell script or
    whatever. Obviously you'll need to work out how to embed octal 33 in
    the string too, to send the ESC itself.

    C has a term "escape sequence" which is used for something completely
    different .if you want to embed a carriage return inside a printf
    string for instance, you would use the escape sequence "\r".
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Jun 15, 2007
    #6
  7. wrote:
    >
    > I got another question. How are escape sequences with [ used in a C
    > source file?
    >

    If you talk about what might be present in a string or similar you
    probably want to keep track of all " and ' too and not count any
    character inside those as unbalanced. A line like this:

    char *str="a string ([\"{ ...";

    Should of course not be counted as having any unbalanced characters that
    needs to be balanced later, neither this:

    char character='(';
    Johan Bengtsson, Jun 15, 2007
    #7
  8. "Johan Bengtsson" <> wrote in message
    news:AHAci.2231$...
    > wrote:
    >>
    >> I got another question. How are escape sequences with [ used in a C
    >> source file?
    >>

    > If you talk about what might be present in a string or similar you
    > probably want to keep track of all " and ' too and not count any
    > character inside those as unbalanced. A line like this:
    >
    > char *str="a string ([\"{ ...";
    >
    > Should of course not be counted as having any unbalanced characters that
    > needs to be balanced later, neither this:
    >
    > char character='(';
    >


    You also have to worry about #ifdefs.
    For example, one might have:
    #ifdef something
    if ( xxx ) {
    ...
    #else
    if ( yyy ) {
    ...
    #endif
    ...
    }

    There are no unbalanced braces in the above code, even though there
    are 2 open braces and only one close brace.
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Aero Stability and Controls Computing
    Fred Kleinschmidt, Jun 15, 2007
    #8
  9. CBFalconer Guest

    Fred Kleinschmidt wrote:
    >

    .... snip ...
    >
    > You also have to worry about #ifdefs.
    > For example, one might have:
    > #ifdef something
    > if ( xxx ) {
    > ...
    > #else
    > if ( yyy ) {
    > ...
    > #endif
    > ...
    > }
    >
    > There are no unbalanced braces in the above code, even though
    > there are 2 open braces and only one close brace.


    Yet whoever wrote it is stark raving mad, and heavily encouraging
    future syntax errors.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Jun 16, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek Simmons
    Replies:
    1
    Views:
    535
    Derek Simmons
    Mar 31, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    346
    Andy Fish
    Nov 19, 2003
  3. Kevin Simonson
    Replies:
    3
    Views:
    431
    Michael Borgwardt
    Nov 28, 2004
  4. Andy Fish
    Replies:
    3
    Views:
    436
    Andy Fish
    Nov 19, 2003
  5. krbyxtrm
    Replies:
    5
    Views:
    528
    krbyxtrm
    Apr 24, 2006
Loading...

Share This Page