找回密码
 注册
X系列官方授权正版
搜索
查看: 3712|回复: 3

[原创] Code... nickname->strid

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis8 ]5 R  a! O3 W2 A' I
  2. # q$ {5 F4 J( l% N5 t
  3. //
    - D, ^4 s! d! m+ g* f' o
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    + `# }+ l9 j9 W1 a
  5. // In case this is not legally possible,
    : T% |) n" L% k# v8 U
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.( W0 s# |9 d7 w3 d4 |! t* W; l
  7. //$ E9 o9 f/ w2 Z9 S2 h+ v/ a1 v

  8. 8 A! Q9 R3 }' }
  9. #include <iostream>  w' z) y" m; ^- d* d
  10. #include <fstream>
    % `& d8 s9 o' G, ^, {
  11. #include <cctype>- }- I, W7 d' _; ?
  12. using namespace std;) I$ E5 W8 a3 T
  13. $ ?/ D( t3 I9 }- h, U
  14. // MACROS/ U- K8 p4 j% @
  15. #define SYSTEM_BLOCK_STR "[system]"& V$ W1 \% e# N
  16. #define NICKNAME_STR "nickname = "
    & h3 M( N( F$ y
  17. #define IDS_STR "strid_name = "4 `( n" w- r+ M8 A9 M) R$ J
  18. //+ ]8 J! i4 w+ o9 G; S3 X

  19. 1 b! X) {  j+ C+ Z
  20. ifstream inf;; V, @: X; c6 Y- ], N$ g: `
  21. char *buffer;' s% r, ~* V" ~' S* z

  22. " |3 {, W' W; G4 m; i% ?0 V
  23. int main(int argc, char *argv[])' g/ x: {3 z% p0 Z5 u! K8 h
  24. {8 @9 z6 K& F, C0 L" j: R
  25.         int i;
    * i6 v  t/ Y! }
  26.        
    " Y7 Z+ ^& `, M7 x
  27.         if(argc!=2){ 4 t4 }# k% [: I
  28.                 cout << "This program requires one and only one argument.";- i/ \6 {, n! @  n: N0 ?3 h4 `
  29.                 return -1;4 {7 P+ a5 M1 d, X& _" N
  30.                 }
    6 W$ w7 a$ M& p+ X0 a) `+ S
  31.         ' Z% B3 {. Y- Y: l1 j( f
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    " P1 M% O$ g1 r$ u5 |7 p
  33.         if(!inf) {: z0 k' M: _3 i. H( @/ V
  34.                 cout << "Error opening file.";
    ; M  i) i2 F1 b$ p8 q
  35.                 return -1;
    5 }, n( R+ x- R, R6 u- g
  36.                 }
    6 D* Q) s  `6 g% N, a
  37.                
    ( M& |5 [0 c: w# o. P) ?# ~
  38.         int streamLength = inf.tellg();8 D1 G8 Y, U2 [: r) k
  39.         if(streamLength!=-1) {' V, O+ ]! O% v, U- G
  40.                 inf.seekg(0, ios::beg);. \$ S+ \! y1 X! E& P7 n+ f
  41.                 2 o+ p: T3 q9 l: n! J
  42.                 buffer = new char [streamLength];
    0 h7 x: p7 w- [# p& R( }7 h
  43.                 // Read file;5 y4 G) k3 z  Y  |% h" i' L/ \
  44.                 for(i=0;i<streamLength;i++) {
    8 f$ t7 `- y7 P! |: Y
  45.                         inf.get(buffer[i]);6 O" ?( J( W" Y! w
  46.                         buffer[i] = tolower(buffer[i]);1 ?+ V9 J0 `+ {) v! y
  47.                         }- l, j: A% U+ p4 j3 t; ]
  48.                
    : ]  h8 k4 q# ^) B4 Q
  49.                 /* For testing6 B1 D0 e$ {/ i3 i1 L
  50.                 for(i=0;i<streamLength;i++) {
    : S: C2 q9 @9 R5 j
  51.                         cout << buffer[i];8 s4 K+ o$ n6 Q4 m! [4 r7 S
  52.                 }
    3 i% P3 H3 a' k. K
  53.                 */
    / R, D5 w( B2 h& ~1 A: R$ [" ^
  54.                 }
    % g. E4 ?% I  J: w5 d. p
  55.         else {* K3 s2 _1 c; q; n% ^
  56.         cout << "Failed to read file." << endl;
    8 D" c, r, @! [0 k& Z
  57.         return -1;
    5 Z4 m  [* X5 ^4 P+ }, V9 ]
  58.         }
    ! h% q" c$ ~0 x6 D+ M* L
  59.         " F2 k6 K; ^2 ^: k3 M
  60.         string processStr (buffer);2 [3 A- C4 C; y, |0 }
  61.         delete [] buffer;
    0 u# V' O2 ]: c. i* d! P  B  Z
  62.        
    5 }2 _! \2 U- A% B. A
  63.         // DUMB DUMB DUMB....$ q) O' F: G2 U: K& A
  64.        
    # q) i7 k" b$ u. M+ R1 m6 P6 m$ {2 N
  65.         int nextSearchPos = 0;; N% c5 x$ q( T, {
  66.         int tmpSearchPos[2] = {0};
    0 t# a# s; r; Z9 |
  67.         int entriesCount = 0;) L2 Z$ ?) i: M7 l
  68.         8 }, h$ a+ Q( L2 n5 E
  69.        
    0 x0 }* {# ?  m" Z3 u5 v
  70.        
    $ H- k# p7 v5 {1 l7 j% B
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
      S* y* _( a: G; Z% f9 {) @
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;5 ]" D6 c) a* Y, _5 U/ B
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    2 M% k- a9 F$ V  O* t+ t5 J
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);
    + z" i! p. S# r7 C- _
  75.                
    + m0 }, j1 ^7 f' ]
  76.                 if(tmpSearchPos[0]!=string::npos) {
    5 e% h2 r9 k( q. ?
  77.                         i=tmpSearchPos[0]+11;) m/ ~3 b! s7 b3 I8 t, I2 z) V2 l
  78.                         6 ~- W. K% w+ f# ~- ?
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    : e6 o- _; [% W7 H$ U
  80.                         cout << processStr[i];% b; X0 b( q0 S/ _" k
  81.                         i++;3 W: ^7 }1 a( ~& \4 m' d
  82.                         }
    ) f' b6 m: N! \" h: s1 v
  83.                         ! p. W: o! r  [5 h7 ]5 f* [
  84.                         cout << endl;. }: }% t' A4 U) j# Y
  85.                        
    - K; ^  }, @7 d0 w6 `. Y
  86.                 }
    $ G( U1 s# {) b1 E: C
  87.                
    * J5 A' V+ z% Y( k& U$ T& f5 g
  88.                 if(tmpSearchPos[1]!=string::npos) {) h0 z' N( J/ Z3 y( l5 g% W
  89.                         i=tmpSearchPos[1]+13;
    * D- r) a; {% r( p
  90.                        
    8 Q/ L4 v7 R9 ^8 ^% r" ]
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    ) w$ n8 a6 D! j5 u6 P
  92.                         cout << processStr[i];
    8 O! c* r( u6 n- R* |
  93.                         i++;8 q! c# M# d- Z3 _& `; q
  94.                         }% |$ U6 K/ I+ ^( V2 P3 |
  95.                        
    # M. K' e1 o, a  H
  96.                         cout << endl;2 `) L' I6 f, p! M' L; M: G3 m. O  {) D
  97.                        
    ! A2 L9 C- f! W+ N
  98.                 }1 Z7 R, t1 T  N
  99.                 % m2 T* X' A1 r
  100.                 entriesCount++;
    ) j3 t4 u7 H# h
  101.         }
    8 u) m8 X) Y8 z
  102.        
    & T; E7 K# T; |
  103.         cout<<entriesCount;
    ! E% T6 {" s5 E) x% j
  104.         return 0;# Q9 |9 h* M  i
  105.        
      ?* u8 `3 O: s2 `  T
  106. }
复制代码
Update: 最后一行输出条目数.
% m# i' |. z7 R4 ^, e8 f- h( R+ o. s* P
[ 本帖最后由 Euyis 于 2008-11-14 22:21 编辑 ]
发表于 2008-11-14 22:04:49 | 显示全部楼层
LOL and WOW, THANKS!!
回复

使用道具 举报

发表于 2009-4-27 21:23:42 | 显示全部楼层
做什么用的啊,看不懂。。。。。楼上高手帮忙讲解一下,谢谢
回复

使用道具 举报

发表于 2009-4-27 21:44:32 | 显示全部楼层
用Nickname来查找DLL里面的Res ID
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Archiver|手机版|小黑屋|DeepTimes.NET 太空游戏站