C parentheses, brackets and brace

C

case.learning

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.
 
K

Kenneth Brody

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:[email protected]>
 
M

Mark McIntyre

On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
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
 
C

case.learning

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.
 
C

case.learning

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'
"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.
 
M

Mark McIntyre

On Fri, 15 Jun 2007 09:24:37 -0700, in comp.lang.c ,
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
 
J

Johan Bengtsson

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='(';
 
F

Fred Kleinschmidt

Johan Bengtsson said:
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.
 
C

CBFalconer

Fred said:
.... 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top