I have had several complaints by some people who wish to help me and I
wish to get the problem straight. I wrote this small utility myself and
added some indentation and I wonder if it is acceptable. It does make source
easier to read.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc!=3) {
fprintf(stderr, "usage error\n");
return -1;
}
double x,y;
x=strtod(argv[1],NULL);
y=strtod(argv[2],NULL);
printf("%.2f\n" ,y/x);
return 0;
}
Is this a good example of a properly indended program?
Bill
Jun 27 '08
43 1992
"CBFalconer " <cb********@yah oo.comwrote in message
news:48******** *******@yahoo.c om...
There is a program around called indent (GNU version 2.2.9 here)
which does all this for you. It is configurable. I use the
following configuration for it (really just one long line in
indent.pro):
-kr -l66 -i3 -bad -di16 -lc66 -nce -ncs -cbi0 -bbo -pmt -psl -ts1
-cdw -ppi 3
This is the results of my program using "indent div.c" which is the name
of the source code.
#include <stdio.h>
#include <stdlib.h>
int
main (int argc, char **argv)
{
if (argc != 3)
{
fprintf (stderr, "usage error\n");
return -1;
}
double x, y;
x = strtod (argv[1], NULL);
y = strtod (argv[2], NULL);
printf ("%.2f\n", y / x);
return 0;
}
Believe me I didn't do this myself. Indent did it for me!
Bill
"Bill Cunningham" <no****@nspam.c omwrites:
"rio" <a@b.cwrote in message
news:48******** *************** @reader4.news.t in.it...
>i like below
#include <stdio.h> #include <stdlib.h>
int main(int argc, char **argv) {double x, y;
if (argc!=3) { fprintf(stderr, "usage error\n"); return -1;}
x=strtod(argv[1], 0); y=strtod(argv[2], 0);
return (x!=0.0) ? (printf("%.2f\n ", y/x), 0): (printf("Error: x==0\n"), -1) ; }
This is the part that goes over my head with my knowledge.
return (x!=0.0) ? /*what's the ? and 0.0 for */
There are things in C, shortcuts that I haven't grasped yet like += and ?: I
do things the long way right now.
I believe "rio" is pulling your leg. His code is gratuitously
obfuscated.
--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nick Keighley wrote:
>
.... snip ...
>
[mutter, one project had a standard of 4 column indent
and 8 space tabs. So you mixed tabs and spaces. eek!]
That is one more reason to use 3 space indentation. Mixing spaces
with tabs is very likely to show up early, and get corrected.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Ben Bacarisse <be********@bsb .me.ukwrites:
Richard Heathfield <rj*@see.sig.in validwrites:
brix99luftballo ns said:
<snip>
till now i've never found a system that pass a 0 as
argc, but it should exist,
maybe on a very small controllers environment...
Macs and Unices aren't that small.
Most systems can be made to pass a zero, but Unices (I prefer *nix)
don't do so as a matter of course.
Ever used ldd? At least on linux it runs the executable with argc==0
which is catched by the dynamic linker. So if your program is dynamicly
linked, you'll never get that case but running by mistaken ldd on a
statically linked executable can lead to that.
Yours,
--
Jean-Marc
Bill Cunningham wrote:
"CBFalconer " <cb********@yah oo.comwrote in message
>There is a program around called indent (GNU version 2.2.9 here) which does all this for you. It is configurable. I use the following configuration for it (really just one long line in indent.pro):
-kr -l66 -i3 -bad -di16 -lc66 -nce -ncs -cbi0 -bbo -pmt -psl -ts1 -cdw -ppi 3
This is the results of my program using "indent div.c" which is
the name of the source code.
.... snip ...
>
Believe me I didn't do this myself. Indent did it for me!
You control it with indent.pro. Just make the line I provided
above available in indent.pro in the directory that contains the
source code you are indenting.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
"Eligiusz Narutowicz" <el************ *@hotmail.comwr ote in message
news:fv******** **@registered.m otzarella.org.. .
Bart <bc@freeuk.comw rites:
>On May 8, 11:33 am, "cr88192" <cr88...@NOSPAM .hotmail.comwro te:
>>"Richard Heathfield" <r...@see.sig.i nvalidwrote in message
news:HM****** *************** *********@bt.co m...
cr88192 said:
<snip>
now, I usually code in notepad,
Oh dear. :-)
all in all it is a good and simple editor...
(So you can write some very complex software but not an editor better than notepad?..)
If you like notepad, you might like to try qed.exe, if you can still find it. (I think an updated version here http://www.movsd.com/qed.htm). It has some useful indent commands. And I believe still smaller than notepad.
Anyone using notepad to write C should be fired. There are lots of
productivity tools which make programming more sure fire and certainly
easier - not to use at least some of them is silly.
I have, personally, never really had that much motivation...
notepad is simple, effective, and edits text files.
I can jump to line numbers, I can search for things, ...
about the only thing it really lacks IMO is a better search-and-replace
feature (so that I don't end up resorting to things like sed, ...). but,
only very rarely is this an issue...
when it comes to C, really, I am not sure what would be added that would
really help all that much...
also note that, often, I have anywhere from 10 to 50 notepad's open at once,
and this was one thing that was a major problem in Vista: it setting a
critically low limit on the number of open windows I could have open before
stuff went weird...
"Eligiusz Narutowicz" <el************ *@hotmail.comwr ote in message
news:fv******** **@registered.m otzarella.org.. .
"cr88192" <cr*****@NOSPAM .hotmail.comwri tes:
<snip>
>> well, as noted, it is a lot more common in C IME, but it is almost never done in C++.
however, I have personally seen a lot more code with the parens than without the parens...
I agree with people who write real apps accessed by many peoples. And
these are:
It is clear and it works.
http://www.linuxjournal.com/article/5780
I will agree with this for the most part, as a general rule the Linux
codebase is fairly readable.
however, I do disagree with it on a few points, namely in that I tend to use
rather different naming conventions (including, on occasion, variants of
hungarian notation, including in function names...).
I do agree that globals should be avoided whenever possible, and especially
not be used between subsystems. however, even there, this is not absolute
(there are some rare cases where I believe this is acceptable).
I tend to encode in the names at least some info about where in the codebase
the code is located, and also because of my modularity practices (this helps
both in avoiding accidental clashes or dependencies, and also in locating
where some particular code is at in the project).
of course, newer languages (such as C++, C#, Java, ...) provide other
mechanisms for this, but it is a tradeoff (shorter easier names, of which
one is no longer certain where exactly in the codebase this function is
located, albeit "jump to" features and similar are common in modern IDE's).
it works...
On 8 May, 22:37, CBFalconer <cbfalco...@yah oo.comwrote:
Nick Keighleywrote:
... snip ...
[mutter, one project had a standard of 4 column indent
and 8 space tabs. So you mixed tabs and spaces. eek!]
That is one more reason to use 3 space indentation. *Mixing spaces
with tabs is very likely to show up early, and get corrected.
you misunderstand. It wasn't an error to mix tabs and spaces
it was compulsary. If you didn't indent with mixed tabs and
spaces you couldn't check your source in!
(actually the checkin system ran your program through
indent and indent was set to this standard)
--
Nick Keighley
"rio" <a@b.cwrote in message
news:48******** *************** @reader4.news.t in.it...
>
"Joe Wright" <jo********@com cast.netha scritto nel messaggio
news:xd******** *************** *******@comcast .com...
>Bill Cunningham wrote:
>> I have had several complaints by some people who wish to help me and I wish to get the problem straight. I wrote this small utility myself and added some indentation and I wonder if it is acceptable. It does make source easier to read.
#include <stdio.h> #include <stdlib.h>
int main(int argc, char **argv) { if (argc!=3) { fprintf(stderr, "usage error\n"); return -1; } double x,y; x=strtod(argv[1],NULL); y=strtod(argv[2],NULL); printf("%.2f\n" ,y/x); return 0; }
Is this a good example of a properly indended program?
>>Bill
i like below
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{double x, y;
if (argc!=3) { fprintf(stderr, "usage error\n"); return -1;}
x=strtod(argv[1], 0);
y=strtod(argv[2], 0);
return (x!=0.0) ?
(printf("%.2f\n ", y/x), 0): (printf("Error: x==0\n"), -1) ;
}
ICK...
these are not exactly the way I would personally use the trinary and comma
operators...
of course, I do have something vaguely similar, but it is more of a
"compact" style:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
double x, y;
if (argc!=3) { fprintf(stderr, "usage error\n"); return(-1); }
x=strtod(argv[1], 0); y=strtod(argv[2], 0);
if(x==0.0) { printf("Error: x==0\n"); return(-1); }
printf("%.2f\n" , y/x), 0); return(0); }
usually, this is done for code that:
I usually wont really be reading or editing much;
my compulsion for reducing vertical space exceeded my need for clarity.
some elements of this style may sometimes be used in ordinary code though.
>
"Bill Cunningham" <no****@nspam.c omha scritto nel messaggio
news:LzJUj.2452 3$qW.3229@trndd c06...
>
"rio" <a@b.cwrote in message
news:48******** *************** @reader4.news.t in.it...
>i like below
#include <stdio.h> #include <stdlib.h>
int main(int argc, char **argv) {double x, y;
if (argc!=3) { fprintf(stderr, "usage error\n"); return -1;}
x=strtod(argv[1], 0); y=strtod(argv[2], 0);
return (x!=0.0) ? (printf("%.2f\n ", y/x), 0): (printf("Error: x==0\n"), -1) ; }
This is the part that goes over my head with my knowledge.
return (x!=0.0) ? /*what's the ? and 0.0 for */
if "x" is 0.0, y/x should be here a seg-fault.
For don't allow this the program says there is an input error because x==0,
and the program return -1 the error code.
There are things in C, shortcuts that I haven't grasped yet like += and ?:
I do things the long way right now.
this is what i like
Bill
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Magnus Lie Hetland |
last post by:
Not many members on the Atox mailing list yet, so I'll venture a
request here...
In Atox 0.2, I've added support for indentation tokens (somewhat like
the Python indentation scheme, but a bit more relaxed). If anyone
finds that sort of thing interesting, please have a look and give me
your opinion -- does it seem like a useful way of dealing with this
sort of thing?
(It seems that lookahead is more sorely needed with indentation, to
|
by: Sateesh |
last post by:
Hi,
I am a beginner in Python, and am wondering what is it about the indentation
in Python, without which python scripts do not work properly.
Why can't the indentation not so strict so as to give better freedom to the
user?
Is there any plausible reason behind this?
Cheers!
Sateesh
|
by: C# Learner |
last post by:
Why is C syntax so uneasy on the eye?
In its day, was it _really_ designed by snobby programmers to scare away
potential "n00bs"? If so, and after 50+ years of programming research,
why are programming languages still being designed with C's syntax?
These questions drive me insane. Every waking minute...
|
by: diffuser78 |
last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding.
Also, using VIM and gedit sometimes.
I had this wierd problem of indentation. My code was 100% right but it
wont run because indentation was not right. I checked time and again
but still no success. I rewrote the code over again in VI and it ran.
Can you please explain whats the trick behind the correct indentation.
Thanks
|
by: John Salerno |
last post by:
How do you make a single string span multiple lines, but also allow
yourself to indent the second (third, etc.) lines so that it lines up
where you want it, without causing the newlines and tabs or spaces to be
added to the string as well?
Example (pretend this is all on one line):
self.DTD = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML
4.01//EN"\n"http://www.w3.org/TR/html4/strict.dtd">\n\n'
| |
by: Xah Lee |
last post by:
Tabs versus Spaces in Source Code
Xah Lee, 2006-05-13
In coding a computer program, there's often the choices of tabs or
spaces for code indentation. There is a large amount of confusion about
which is better. It has become what's known as “religious war” —
a heated fight over trivia. In this essay, i like to explain what is
the situation behind it, and which is proper.
|
by: bearophileHUGS |
last post by:
This is the best praise of semantic indentation I have read so far, by
Chris Okasaki:
http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html
A quotation:
I have appreciated that article, and I have personally seen how fast
students learn Python basics compared to other languages, but I think
that it's way more than just indentation that makes the Python
language so quick to learn .
|
by: Eric S. Johansson |
last post by:
in trying to make programming in Python more accessible to disabled programmers
(specifically mobility impaired speech recognition users), and hitting a bit of
a wall. The wall (for today) is indentation. I need a method of getting the
"right indentation" without having to speak a bunch of unnecessary commands.
For example, depth specified by the previous line. But, frequently you need to
go to a more arbitrary indentation for example...
|
by: Eric S. Johansson |
last post by:
Almar Klein wrote:
there's nothing like self interest to drive one's initiative. :-) 14 years with
speech recognition and counting. I'm so looking to my 15th anniversary of being
injured next year....
another initiative is exporting the speech recognition environment to the Linux
context. In a nutshell, he dictated to application on Windows, it tunnels over
the network to a Linux machine, and will allow you to cut and paste to and...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |