473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C parentheses, brackets and brace

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
8 4564
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
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: deko | last post by:
Do I need to use curly brackets in PHP if .. else statements? other constructs? Does it matter? What are Best Practices? Why? thanks in advance... This seems to work WITHOUT curly brackets:...
44
by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
1
by: Robert Hanson | last post by:
Any idea on how to find a matching bracket in VS.Net?? Thanks in advance, Bob Hanson
9
by: Cristof Falk | last post by:
I'm using VS.NET 2002 w/C# on one project. I'd like it to, when defining a new method, to automatically put the {} brackets automatically. I prefer having brackets closed before coding. Right now,...
4
by: Jason Kendall | last post by:
How do I use a curly brace within a string passed to String.Format? I want to pass a string that includes a curly brace, but that curly brace is not being used to indicate a replacable format...
7
by: zheetee | last post by:
<script type="text/vbscript"> sub setTextBoxValue(a1,a2) thedelete.deleteTextBox.value = a1 end sub </script> <td> <a href="#"...
16
by: Mark Rae | last post by:
Hi, Supposing I had a string made up of a person's name followed by their profession in parentheses e.g. string strText = "Tiger Woods (golfer)"; and I wanted to extract the portion of the...
37
by: dorayme | last post by:
Is there some particular reason that the inventors of CSS chose to leave us with the legacy of the curly brackets (for which one has to shift press) rather than the square (for which one simply...
2
by: Peter Proost | last post by:
Hi group I'm searching for a regex to retrieve the values from between the brackets. For example if I've got this text: ({CP-2} x {EDP-2}) / 1000 = {KGP-2} = f Prix de base = f + VA (fixe...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.