大家可以先思考,想想如何写出这样的代码,然后再看看下面的代码是否与你的思路差不多。
注意: 展开后有很长一段字符数组定义(char sz[]=....)
Code
#include <stdio.h>
#include <string.h>
char sz[] = {0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6f,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x72,0x69,0x6e,0x67,0x2e,0x68,0x3e,0x0a,0x63,0x68,0x61,0x72,0x20,0x73,0x7a,0x5b,0x5d,0x20,0x3d,0x20,0x7b,0x25,0x73,0x7d,0x3b,0x0a,0x69,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x69,0x6e,0x74,0x20,0x69,0x3b,0x0a,0x63,0x68,0x61,0x72,0x20,0x62,0x75,0x66,0x5b,0x34,0x30,0x39,0x36,0x30,0x5d,0x3b,0x0a,0x63,0x68,0x61,0x72,0x20,0x66,0x6d,0x74,0x5b,0x5d,0x20,0x3d,0x20,0x7b,0x30,0x78,0x33,0x30,0x2c,0x30,0x78,0x37,0x38,0x2c,0x30,0x78,0x32,0x35,0x2c,0x30,0x78,0x33,0x30,0x2c,0x30,0x78,0x33,0x32,0x2c,0x30,0x78,0x37,0x38,0x2c,0x30,0x7d,0x3b,0x0a,0x66,0x6f,0x72,0x28,0x20,0x69,0x20,0x3d,0x20,0x30,0x20,0x3b,0x20,0x69,0x20,0x3c,0x20,0x73,0x69,0x7a,0x65,0x6f,0x66,0x28,0x73,0x7a,0x29,0x20,0x3b,0x20,0x69,0x20,0x2b,0x2b,0x20,0x29,0x0a,0x7b,0x0a,0x69,0x66,0x28,0x20,0x69,0x20,0x3e,0x20,0x30,0x20,0x29,0x20,0x73,0x74,0x72,0x63,0x61,0x74,0x28,0x20,0x62,0x75,0x66,0x2c,0x20,0x22,0x2c,0x22,0x20,0x29,0x3b,0x0a,0x73,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x20,0x62,0x75,0x66,0x2b,0x69,0x2a,0x35,0x2c,0x20,0x66,0x6d,0x74,0x2c,0x20,0x73,0x7a,0x5b,0x69,0x5d,0x20,0x29,0x3b,0x0a,0x7d,0x0a,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x20,0x73,0x7a,0x2c,0x20,0x62,0x75,0x66,0x20,0x29,0x3b,0x0a,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x3b,0x0a,0x7d,0x0a,0x00};
int main()
{
int i;
char buf[40960];
char fmt[] = {0x30,0x78,0x25,0x30,0x32,0x78,0};
for( i = 0 ; i < sizeof(sz) ; i ++ )
{
if( i > 0 ) strcat( buf, "," );
sprintf( buf+i*5, fmt, sz[i] );
}
printf( sz, buf );
return 0;
}
#include <stdio.h>
#include <string.h>
char sz[] = {0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6f,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x72,0x69,0x6e,0x67,0x2e,0x68,0x3e,0x0a,0x63,0x68,0x61,0x72,0x20,0x73,0x7a,0x5b,0x5d,0x20,0x3d,0x20,0x7b,0x25,0x73,0x7d,0x3b,0x0a,0x69,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x69,0x6e,0x74,0x20,0x69,0x3b,0x0a,0x63,0x68,0x61,0x72,0x20,0x62,0x75,0x66,0x5b,0x34,0x30,0x39,0x36,0x30,0x5d,0x3b,0x0a,0x63,0x68,0x61,0x72,0x20,0x66,0x6d,0x74,0x5b,0x5d,0x20,0x3d,0x20,0x7b,0x30,0x78,0x33,0x30,0x2c,0x30,0x78,0x37,0x38,0x2c,0x30,0x78,0x32,0x35,0x2c,0x30,0x78,0x33,0x30,0x2c,0x30,0x78,0x33,0x32,0x2c,0x30,0x78,0x37,0x38,0x2c,0x30,0x7d,0x3b,0x0a,0x66,0x6f,0x72,0x28,0x20,0x69,0x20,0x3d,0x20,0x30,0x20,0x3b,0x20,0x69,0x20,0x3c,0x20,0x73,0x69,0x7a,0x65,0x6f,0x66,0x28,0x73,0x7a,0x29,0x20,0x3b,0x20,0x69,0x20,0x2b,0x2b,0x20,0x29,0x0a,0x7b,0x0a,0x69,0x66,0x28,0x20,0x69,0x20,0x3e,0x20,0x30,0x20,0x29,0x20,0x73,0x74,0x72,0x63,0x61,0x74,0x28,0x20,0x62,0x75,0x66,0x2c,0x20,0x22,0x2c,0x22,0x20,0x29,0x3b,0x0a,0x73,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x20,0x62,0x75,0x66,0x2b,0x69,0x2a,0x35,0x2c,0x20,0x66,0x6d,0x74,0x2c,0x20,0x73,0x7a,0x5b,0x69,0x5d,0x20,0x29,0x3b,0x0a,0x7d,0x0a,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x20,0x73,0x7a,0x2c,0x20,0x62,0x75,0x66,0x20,0x29,0x3b,0x0a,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x3b,0x0a,0x7d,0x0a,0x00};
int main()
{
int i;
char buf[40960];
char fmt[] = {0x30,0x78,0x25,0x30,0x32,0x78,0};
for( i = 0 ; i < sizeof(sz) ; i ++ )
{
if( i > 0 ) strcat( buf, "," );
sprintf( buf+i*5, fmt, sz[i] );
}
printf( sz, buf );
return 0;
}
BTW,代码是我的同事LiuB完成的,必须得提及一下,不然会被K的。。。:)