473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4592
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
ca***********@g mail.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***********@g mail.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...@s pamcop.netwrote :
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,

case.learn...@g mail.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...@g mail.com wrote:
On Jun 15, 9:52 am, Mark McIntyre <markmcint...@s pamcop.netwrote :
On Fri, 15 Jun 2007 08:46:58 -0700, in comp.lang.c ,
case.learn...@g mail.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***********@g mail.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***********@g mail.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*******@hotm ail.comwrote in message
news:AH******** ********@newsb. telia.net...
ca***********@g mail.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.securityfoc us.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
12961
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: if(ereg("Win", getenv("HTTP_USER_AGENT"))) $visos = "Windows"; elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC",
44
3373
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 expression such as x = (5) * (4+6). Wouldn't it have been better to define tuples with <>'s or {}'s or something else to avoid this confusion?? Perhaps ()'s are a good idea for some other reason I don't know?
1
2903
by: Robert Hanson | last post by:
Any idea on how to find a matching bracket in VS.Net?? Thanks in advance, Bob Hanson
9
2533
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, one has to type the open bracket, then hit enter, then delete a tab, then type the close bracket, then go to the open bracket and hit enter. I thought I read that the IDE would do this automatically. Does later versions do this in the way I...
4
6691
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 parameter. Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}", Date.Now) Thanks. -Jason Kendall
7
5238
by: zheetee | last post by:
<script type="text/vbscript"> sub setTextBoxValue(a1,a2) thedelete.deleteTextBox.value = a1 end sub </script> <td> <a href="#" onclick="setTextBoxValue('<%#Container.DataItem("SerialNumber")%>','<%#Container.DataItem("EquipmentCategory")%>')">
16
9374
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 string between the parentheses i.e. "golfer"
37
2519
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 has to press)? p is two key presses shorter then p {margin: 0;}
2
2512
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 jusqu’au {TWD}) = {KGP-2} + {TW} = {(KGP-2) + TW}
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.