By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

C parentheses, brackets and brace

P: n/a
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 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
ca***********@gmail.com 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
Jun 15 '07 #2

P: n/a
ca***********@gmail.com 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:Th*************@gmail.com>

Jun 15 '07 #3

P: n/a
On Jun 15, 9:52 am, Mark McIntyre <markmcint...@spamcop.netwrote:
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,

case.learn...@gmail.com 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 '07 #4

P: n/a
On Jun 15, 10:02 am, case.learn...@gmail.com wrote:
On Jun 15, 9:52 am, Mark McIntyre <markmcint...@spamcop.netwrote:
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
case.learn...@gmail.com 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 '07 #5

P: n/a
On Fri, 15 Jun 2007 09:24:37 -0700, in comp.lang.c ,
ca***********@gmail.com 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
Jun 15 '07 #6

P: n/a
ca***********@gmail.com 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='(';

Jun 15 '07 #7

P: n/a

"Johan Bengtsson" <qw*******@hotmail.comwrote in message
news:AH****************@newsb.telia.net...
ca***********@gmail.com 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

Jun 15 '07 #8

P: n/a
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

Jun 16 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.