缩进 [英] indentation
问题描述
有些人希望帮助我,我有几次投诉,我希望b $ b希望直接解决问题。我自己写了这个小实用程序,并且
添加了一些缩进,我想知道它是否可以接受。它确实使源
更容易阅读。
#include< stdio.h>
#include< stdlib。 h>
int main(int argc,char ** argv){
if(argc!= 3){
fprintf(stderr,usage error \ n);
返回-1;
}
double x,y;
x = strtod(argv [1],NULL);
y = strtod(argv [2],NULL);
printf("%。 2f \ n,y / x);
返回0;
}
这是一个很好的例子正确的程序?
比尔
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
推荐答案
Bill Cunningham写道:
Bill Cunningham wrote:
我曾经有一些人希望帮助我,而且我希望能够直接解决问题。我自己写了这个小实用程序,并且
添加了一些缩进,我想知道它是否可以接受。它确实使源
更容易阅读。
#include< stdio.h>
#include< stdlib。 h>
int main(int argc,char ** argv){
if(argc!= 3){
fprintf(stderr,usage error \ n);
返回-1;
}
double x,y;
x = strtod(argv [1],NULL);
y = strtod(argv [2],NULL);
printf("%。 2f \ n,y / x);
返回0;
}
这是一个很好的例子正确的indended程序?
比尔
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
找到GNU''缩进''实用程序。它给了我们..
#include< stdio.h>
#include< stdlib.h>
int main(int argc,char ** argv)
{
if(argc!= 3){
fprintf(stderr ,使用错误\ n);
返回-1;
}
双x,y;
x = strtod(argv [1],NULL);
y = strtod(argv [2],NULL);
printf("%。2f \ n",y / x);
返回0;
}
...将您的程序作为输入。你觉得怎么样?
-
Joe Wright
所有东西应尽可能简单,但不能更简单。
---阿尔伯特爱因斯坦---
Find the GNU ''indent'' utility. It gives us..
#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;
}
...given your program as input. What do you think?
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Bill Cunningham写道:
Bill Cunningham wrote:
>
我曾经有一些人希望帮助我
并且我希望直接解决问题。我自己写了这个小实用工具
并添加了一些缩进,我想知道它是否可以接受。
它确实使源更容易阅读。
#include< stdio.h>
#include< stdlib.h>
int main(int argc,char ** argv ){
if(argc!= 3){
fprintf(stderr,usage error \ n);
返回 - 1;
}
double x,y;
x = strtod(argv [1],NULL);
y = strtod(argv [2],NULL);
printf("%。2f \ n",y / x);
返回0;
}
这是一个适当加入程序的好例子吗?
>
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?
关闭。主要问题是压痕太少(我建议3
空格)和源中缺少空格。此外,变量
声明不应出现在可执行代码之后。比较下面的
:
#include< stdio.h>
#include< stdlib.h>
int main(int argc,char ** argv){
double x,y;
if(argc != 3){
fprintf(stderr,usage error \ n);
返回-1;
}
x = strtod(argv [1],NULL);
y = strtod(argv [2],NULL);
printf("%。 2f \ n,y / x);
返回0;
} / *主* /
我喜欢使用函数
名称标记函数的右大括号。
有一个名为indent的程序(GNU 2.2.9版本)
为你做这一切。它是可配置的。我使用
以下配置(实际上只需要一个长行/ $
indent.pro):
-kr - l66 -i3 -bad -di16 -lc66 -nce -ncs -cbi0 -bbo -pmt -psl -ts1
-cdw -ppi 3
-
[mail]:Chuck F(cinefalconer at maineline dot net)
[page]:< http://cbfalconer.home.att.net>
尝试下载部分。
**来自 http: //www.teranews.com **
Close. The main problems are too little indentation (I suggest 3
spaces) and the lack of spaces in the source. Also the variable
declaration should not occur after executable code. Compare the
following:
#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], NULL);
y = strtod(argv[2], NULL);
printf("%.2f\n", y/x);
return 0;
} /* main */
I like to mark the closing brace of a function with the function
name.
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
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
" Joe Wright" < jo ******** @ comcast.netwrote in message
news:xd ********************** ********@comcast.com。 ..
"Joe Wright" <jo********@comcast.netwrote in message
news:xd******************************@comcast.com. ..
..将您的程序作为输入。您怎么看?
..given your program as input. What do you think?
我写的文件的第一个副本已经通过
更改了新闻服务器或客户端的缩进。当我发布它并且
缩进被删除时它缩进了。也许nntp会这样做。 progran原本是这样缩进的。
if(argc!3){
fprintf(stderr," usage)错误\ n");
返回-1;
}
那是复制到帖子上的内容张贴没有
缩进。
比尔
The first copy of the file I wrote has had its indentation changed by
the news server or client. It was indented when I posted it and the
indentation was removed. Maybe nntp does that. The progran was originally
indented like this.
if (argc!3) {
fprintf(stderr,"usage error\n");
return -1;
}
Thatis what was copied onto the post and it was posted without the
indentation.
Bill
这篇关于缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!