• 全部
...

一段特别有意思的代码引申出的几个问题,请大大大大虾进来给小弟解释一下,谢谢.

appleing 2004-09-15 03:17:46
今天在某地看到一段代码,觉得特别有意思,如下:

#include <stdio.h>
main(_){char*x="*b#**000**I#*******2*0***#-.****5.*-#-.****54.#*******2**6#****00**0.#";
while(_=*x/4)_-=8,printf("\n%*s"+!!_,_+_,"_/_/_/"+*x++%4*2);}

这段代码就是打印出一个"knock"的字母banner.

具体他是怎么实现的我不太关心,毕竟这种一点可读性都没有的代码还是少学为好..呵呵.

可是之中有两个地方我想弄懂,大家一起讨论哈.



问题1:

printf("\n%*s"...

这个"%*s"是什么类型的参数,printf有这种隐藏参数吗?做什么用的?如果有人有比较完整的printf参数的资料,还望share一下.

问题2:

接着问题1,("\n%*s"+!!_,

这个是一个字符串和一个变量相加吗?可以这样用吗,这两个"!!"号是两个求反运算吗?

谢谢.
...全文
给本帖投票
571 29 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
argenCHN 2004-09-16
  • 打赏
  • 举报
回复
太牛了,这也想得出来
cnred 2004-09-16
  • 打赏
  • 举报
回复
域名注册、空间租用、邮件系统、网站建设、智能建站、网站推广、动态域名、通用网址、网络实名


中国红电子商务频道,

强大的主机管理系统,实时开通,免费试用7天,满意再付款

成为我们的代理,将有更多惊喜!

浓情夏日优惠酬谢:
7月1日—8月30日,
国际域名78元,
国内域名178元,
50MASP空间+国际域名188元;
90MASP空间+国际域名218元;

购买本站任意一款空间+68元即可获得国际域名(.com/.net/.org)
+158元即可获得国内.cn域名(.com.cn/.net.cn/.org.cn/.cn)

我们的网站是:http://www.cnred.net

TEL:0755--61325102 QQ:380743590
Email: ccc@cnred.net
cnred 2004-09-16
  • 打赏
  • 举报
回复
域名注册、空间租用、邮件系统、网站建设、智能建站、网站推广、动态域名、通用网址、网络实名


中国红电子商务频道,

强大的主机管理系统,实时开通,免费试用7天,满意再付款

成为我们的代理,将有更多惊喜!

浓情夏日优惠酬谢:
7月1日—8月30日,
国际域名78元,
国内域名178元,
50MASP空间+国际域名188元;
90MASP空间+国际域名218元;

购买本站任意一款空间+68元即可获得国际域名(.com/.net/.org)
+158元即可获得国内.cn域名(.com.cn/.net.cn/.org.cn/.cn)

我们的网站是:http://www.cnred.net

TEL:0755--61325102 QQ:380743590
Email: ccc@cnred.net
appleing 2004-09-16
  • 打赏
  • 举报
回复
谢谢谢谢,谢谢这么多人慷慨发炎,我也差不多懂了,哈哈哈,结帖.
迷你苑 2004-09-15
  • 打赏
  • 举报
回复
我现在弄清楚一件事了,不怎的原因,但是我在TC2.0验证了一下。

printf("%*s",*x);
%*s的 意思是输出空格,空格的个数,和后面的参数有关,后面的参数的十进制就几,那空格的个数就是几个
248406869 2004-09-15
  • 打赏
  • 举报
回复
to :kevin_wang(砸锅卖铁)
编译过,你要把文件的扩展名改为.c而不是.cpp.
同桌老王 2004-09-15
  • 打赏
  • 举报
回复
void main(a)
{
}
你可以在vc6中编译通过?
248406869 2004-09-15
  • 打赏
  • 举报
回复
楼上的变量是可以不写类型的,一开始我也不知道,刚知道的。
同桌老王 2004-09-15
  • 打赏
  • 举报
回复
这样的代码编译不通过
从来没有听说过一个变量没有类型的。
248406869 2004-09-15
  • 打赏
  • 举报
回复
“"_"是个整型变量相当于int argc,可能是在主函数中可以不写类型”。我说错了,所有函数的参数都可以不写类型和返回类型默认为整形。
248406869 2004-09-15
  • 打赏
  • 举报
回复
补充。_+_是前面的"*"的参数,_+_定义了长度,如果字符长度比这个值大则输出整个字符串否则补空格。这是用来输出空格的。
248406869 2004-09-15
  • 打赏
  • 举报
回复
我分析main(_),"_"是个整型变量相当于int argc,可能是在主函数中可以不写类型(猜测),他开始值是1。
while(_=*x/4)_-=8,printf("\n%*s"+!!_,_+_,"_/_/_/"+*x++%4*2);
前面是个while语句while(_=*x/4),后面是个逗号表达式,_-=8是为了改变变量“_”的值,后面调用printf函数。%*s我没用过上面有位朋友说过了。"\n%*s"+!!_,这是printf的第一个参数,是规定打印格式的,“!!_”非0就是1,字符串是表示为指针的例如:*"abc"是a,*("abc"+1)是b。"\n%*s"+!!_不是"\n%*s"就是"n%*s",由!!_决定是控制换行的。_+_是前面的"*"的参数吧?(我不知道)."_/_/_/"+*x++%4*2和前面的"\n%*s"+!!_原理一样.
knocker 2004-09-15
  • 打赏
  • 举报
回复
代码的维护??
这代码需要“维护”吗?他们自称为“精英文化”。我也觉得有点象书法中的草书的味道,有点意思。不过,我花了5小时还没完全搞清程序的流程,菜啊,有待高手解读。
Smidin 2004-09-15
  • 打赏
  • 举报
回复
好玩!但不实用!!
谁要是做这段代码的维护,绝对翘辫子!!
nocool 2004-09-15
  • 打赏
  • 举报
回复
关注
HUHUJUNJIE 2004-09-15
  • 打赏
  • 举报
回复
The second optional field of the format specification is the width specification. The width argument is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values — depending on whether the – flag (for left alignment) is specified — until the minimum width is reached. If width is prefixed with 0, zeros are added until the minimum width is reached (not useful for left-aligned numbers).

The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width is not given, all characters of the value are printed (subject to the precision specification).

If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list. A nonexistent or small field width does not cause the truncation of a field; if the result of a conversion is wider than the field width, the field expands to contain the conversion result.

goodname 2004-09-15
  • 打赏
  • 举报
回复
vc6的汇编代码
--------------------------------------------------------------
#include <stdio.h>
main(_){char*x="*b#**000**I#*******2*0***#-.****5.*-#-.****54.#*******2**6#****00**0.#";
00401010 push ebp
00401011 mov ebp,esp
00401013 sub esp,48h
00401016 push ebx
00401017 push esi
00401018 push edi
00401019 lea edi,[ebp-48h]
0040101C mov ecx,12h
00401021 mov eax,0CCCCCCCCh
00401026 rep stos dword ptr [edi]
00401028 mov dword ptr [ebp-4],offset string "*b#**000**I#*******2*0***#-.****"... (0042002c)
15: while(_=*x/4)_-=8,printf("\n%*s"+!!_,_+_,"_/_/_/"+*x++%4*2);}
0040102F mov eax,dword ptr [ebp-4]
00401032 movsx eax,byte ptr [eax]
00401035 cdq
00401036 and edx,3
00401039 add eax,edx
0040103B sar eax,2
0040103E mov dword ptr [ebp+8],eax
00401041 cmp dword ptr [ebp+8],0
00401045 je main+8Ah (0040109a)
00401047 mov ecx,dword ptr [ebp+8]
0040104A sub ecx,8
0040104D mov dword ptr [ebp+8],ecx
00401050 mov edx,dword ptr [ebp-4]
00401053 movsx eax,byte ptr [edx]
00401056 and eax,80000003h
0040105B jns main+52h (00401062)
0040105D dec eax
0040105E or eax,0FCh
00401061 inc eax
00401062 lea ecx,[eax*2+420024h]
00401069 mov dword ptr [ebp-8],ecx
0040106C mov edx,dword ptr [ebp-8]
0040106F push edx
00401070 mov eax,dword ptr [ebp+8]
00401073 add eax,dword ptr [ebp+8]
00401076 push eax
00401077 xor ecx,ecx
00401079 cmp dword ptr [ebp+8],0
0040107D setne cl
00401080 add ecx,offset string "\n%*s" (0042001c)
00401086 push ecx
00401087 mov edx,dword ptr [ebp-4]
0040108A add edx,1
0040108D mov dword ptr [ebp-4],edx
00401090 call printf (004010e0)
00401095 add esp,0Ch
00401098 jmp main+1Fh (0040102f)
0040109A pop edi
0040109B pop esi
0040109C pop ebx
0040109D add esp,48h
004010A0 cmp ebp,esp
004010A2 call __chkesp (00401160)
004010A7 mov esp,ebp
004010A9 pop ebp
004010AA ret
wupangzi 2004-09-15
  • 打赏
  • 举报
回复
学习!
zgy166 2004-09-15
  • 打赏
  • 举报
回复
期待高手
lw549 2004-09-15
  • 打赏
  • 举报
回复
呵呵,好玩
加载更多回复(9)

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部