请评论 [英] Comments please

查看:41
本文介绍了请评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此函数用于打印保证为

格式的字符串MM / DD / YYYY(假设< stdio.h>和< string.h>包括在内)为

YYYY-MM-DD:


void printdate(const char * date)

{

char tdate [10],* cp;

int mod = 10,i;


cp = tdate;

for( i = 6; i%mod!= 5; ++ i,++ cp){

if(!(i%mod))

*(cp ++)= '' - '';

* cp = date [i%mod];

}

* cp = 0;

* strchr(tdate,''/'')='' - '';

printf(新日期是%s \ n,tdate);

}


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

This function is intended to print a string guaranteed to be in the
form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as
YYYY-MM-DD:

void printdate( const char *date )
{
char tdate[10], *cp;
int mod=10, i;

cp=tdate;
for( i=6 ; i%mod != 5 ; ++i, ++cp ) {
if( !(i%mod) )
*(cp++)=''-'';
*cp=date[i%mod];
}
*cp=0;
*strchr( tdate, ''/'' )=''-'';
printf( "New date is %s\n", tdate );
}

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

推荐答案

Christopher Benson-Manica写道:
Christopher Benson-Manica wrote:
此函数用于打印字符串保证以
形式MM / DD / YYYY(假设< stdio.h>和< string.h>包括在内)为
YYYY-MM-DD:
This function is intended to print a string guaranteed to be in the
form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as
YYYY-MM-DD:




也许我在这里是少数,但不是代码更复杂

比它需要的多吗?如果您确保输入格式为某种格式,为什么还需要所有复杂的代码呢?


对我而言,似乎程序员正在尝试表明他有多聪明。


-

gabriel



Maybe i''m in the minority here, but isn;t that code waay more complicated
than it needs to be? If you have input guaranteed to be in a certain
format, why do you need all that complex code?

To me it seems like the programmer is trying to show how smart he is.

--
gabriel


Christopher Benson-Manica写道:
Christopher Benson-Manica wrote:
此函数用于打印保证为
形式的字符串MM / DD / YYYY(假设包含< stdio.h>和< string.h>) as
YYYY-MM-DD:

void printdate(const char * date)
{char / cdate [10],* cp;
int mod = 10,i;

cp = tdate;
for(i = 6; i%mod!= 5; ++ i,++ cp){
if( !(i%mod))
*(cp ++)='' - '';
* cp = date [i%mod];
}
* cp = 0;
* strchr(tdate,''/'')='' - '';
printf(新日期是%s \ n,tdate);
}
This function is intended to print a string guaranteed to be in the
form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as
YYYY-MM-DD:

void printdate( const char *date )
{
char tdate[10], *cp;
int mod=10, i;

cp=tdate;
for( i=6 ; i%mod != 5 ; ++i, ++cp ) {
if( !(i%mod) )
*(cp++)=''-'';
*cp=date[i%mod];
}
*cp=0;
*strchr( tdate, ''/'' )=''-'';
printf( "New date is %s\n", tdate );
}




/ *

此功能用于打印st保证在

表格MM / DD / YYYY(假设< stdio.h>和< string.h>包括)作为

YYYY-MM-DD:

* /

void printdate(const char * date)

{

printf(新日期是%s - %。2s - %。2s \ n,strrchr(日期,''/'')+ 1,日期,strchr( date,''/'')+ 1);

}


Jeremy。



/*
This function is intended to print a string guaranteed to be in the
form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as
YYYY-MM-DD:
*/
void printdate(const char *date)
{
printf( "New date is %s-%.2s-%.2s\n", strrchr(date, ''/'') + 1, date, strchr(date, ''/'') + 1);
}

Jeremy.




2004年1月19日星期一,Christopher Benson-Manica写道:

On Mon, 19 Jan 2004, Christopher Benson-Manica wrote:

此函数用于打印保证在
中的字符串表格MM / DD / YYYY(假设< stdio.h>和< string.h>包含在内)作为
YYYY-MM-DD:


Jeremy Yallop有在头上敲了一下钉子这段代码不必要的复杂性。但是,我只想指出......

void printdate(const char * date)
{
char tdate [10],* cp;
int mod = 10,i;

cp = tdate;
for(i = 6; i%mod!= 5; ++ i,++ cp){


....你给了一个奇怪的名字,明显正确的魔法

数字(10,如10基数),但保留在任意的魔术数字

6和5,其中我甚至不能说出他们应该是什么。

[事实上,你是*不是*使用10来表示基数为10,因为我看到你通过它来修改东西时假定为
。我认为这是一个硬编码的字符串长度。那真是太傻了。]

if(!(i%mod))


if(i%10 == 0)

*(cp ++)='' - '';


就个人而言,我不会在

''* cp ++''上添加多余的括号,但也许是某些专家的MMV出于某些不明原因

我不知道。

* cp = date [i%mod];
}
* cp = 0;


我是一个相信制作空字符的阵营

在视觉上与整数零不同。 * cp =''\'''。 YMMV。

* strchr(tdate,''/'')='' - '';
printf(新日期是%s \ n,tdate);
}

This function is intended to print a string guaranteed to be in the
form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as
YYYY-MM-DD:
Jeremy Yallop has hit the nail on the head w.r.t. the unnecessary
complexity of this code. However, I''d just like to point out...
void printdate( const char *date )
{
char tdate[10], *cp;
int mod=10, i;

cp=tdate;
for( i=6 ; i%mod != 5 ; ++i, ++cp ) {
....that you''ve given a weird name to the obviously-correct magic
number (10, as in base-10), but kept in the "arbitrary" magic numbers
6 and 5, of which I can''t even tell what they''re supposed to be.
[And in fact, you''re *not* using the 10 to mean base-10, as I
assumed upon seeing you mod''ing things by it. It''s a hard-coded
string length, I think. That''s just silly.]
if( !(i%mod) )
if (i%10 == 0)
*(cp++)=''-'';
Personally, I would not add the redundant parenthesization on
''*cp++'', but perhaps some expert''s MMV for some obscure reason of
which I am unaware.
*cp=date[i%mod];
}
*cp=0;
I am of the camp that believes in making the null character
visually distinct from the integer zero. *cp = ''\0''. YMMV.
*strchr( tdate, ''/'' )=''-'';
printf( "New date is %s\n", tdate );
}




当然,在一个字符串中执行I / O会很奇怪

解析函数。模块化不良。即使它只是一个

的例子,即使你产生了关于有多少种方式的讨论,否则.b
必须返回字符串。 ;-)


HTH,

-Arthur



And naturally it''s kind of weird to be doing I/O in a string
parsing function. Bad modularization. Even if it is only an
example, and even if you''d spawn discussions about how many ways
C has to return strings, otherwise. ;-)

HTH,
-Arthur


这篇关于请评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆