问题描述
此函数用于打印保证为
格式的字符串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.
推荐答案
也许我在这里是少数,但不是代码更复杂
比它需要的多吗?如果您确保输入格式为某种格式,为什么还需要所有复杂的代码呢?
对我而言,似乎程序员正在尝试表明他有多聪明。
-
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
/ *
此功能用于打印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.
当然,在一个字符串中执行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
这篇关于请评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!