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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis) V' ?, c) E3 n9 W
  2. ' {0 u0 Q/ I* j9 f
  3. //* w6 O6 y) S% x' j
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    8 X5 [+ b" E1 j* n* m* e  N$ |7 k
  5. // In case this is not legally possible,3 h( q. d: n$ x3 p
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.
    ' t  o* D2 ^4 W$ C
  7. //
    ! ~& G0 S4 T% Q! ^- Q# `
  8. 5 i7 @, T) t+ a  H4 e
  9. #include <iostream>
    & B) L. Z8 c7 O; y- x0 R
  10. #include <fstream>5 i' C% V% F. F" U) h+ |; S  B
  11. #include <cctype>6 l8 n8 [3 k9 o6 k" b
  12. using namespace std;) C6 ~+ H6 f. c* c( y. V

  13. 8 T2 t( j7 A! [# Q" i
  14. // MACROS
    * e4 ^; q% a3 T
  15. #define SYSTEM_BLOCK_STR "[system]") _6 Z  s% ?$ n. v4 R
  16. #define NICKNAME_STR "nickname = "
    ) r# q6 B6 j( o+ ~
  17. #define IDS_STR "strid_name = "; r! h: K* t3 B3 u
  18. //7 ?; E8 S! ]& _- _. y* N
  19. ( E- m8 R: {. r( S0 D% g
  20. ifstream inf;2 L1 l# [. n! g
  21. char *buffer;! Q+ X( }2 t( Q! f/ |
  22. 1 f% K6 _0 C; \+ F. {9 N* T
  23. int main(int argc, char *argv[])
    # @8 D* B. G* R0 \' J
  24. {
    7 i( n! E* \/ Y5 a8 B! `+ T
  25.         int i;3 O& l, u) v/ c( {8 H1 B
  26.         6 B7 {/ n) J" c
  27.         if(argc!=2){   Y5 x- f- f( p8 E" g6 A
  28.                 cout << "This program requires one and only one argument.";
    % W. J' I; L- {: z& m8 y" c6 j- |, Q
  29.                 return -1;
    + x6 U9 `" a6 b3 K' T
  30.                 }1 Z% a) H3 Q3 P6 P, j
  31.         ( q* d! |5 [$ @/ R+ c) }; h1 c* L
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    / R: E8 U  t9 W6 H) S) N
  33.         if(!inf) {
    0 S; p) q9 W5 M7 u; t
  34.                 cout << "Error opening file.";
    9 G7 a, H( j; O& P8 Z
  35.                 return -1;8 A' L! z* L0 R# U9 S# {# a  o2 |8 B
  36.                 }* D; O' f0 b  {# D  K* k
  37.                 * f/ ^0 v9 s% J
  38.         int streamLength = inf.tellg();4 r# V2 o, j1 j% L
  39.         if(streamLength!=-1) {
    ( @4 F( {/ s, a3 y
  40.                 inf.seekg(0, ios::beg);
    $ E; I3 d0 ]$ _) t* U, m
  41.                 1 N' v  O4 ~; D2 S0 Y" h
  42.                 buffer = new char [streamLength];" s6 l, q1 G; {  [$ b
  43.                 // Read file;8 _. X+ Q0 O) Z
  44.                 for(i=0;i<streamLength;i++) {
    ! N4 S; W/ r0 H/ M" K, V- C$ D& \
  45.                         inf.get(buffer[i]);* S* B+ z! \, _( b5 Y" x
  46.                         buffer[i] = tolower(buffer[i]);2 f, x, e" a( S9 z) F8 s! f
  47.                         }
    * R9 E; g; W/ {# d5 [) y
  48.                 0 y, F1 f3 [, S4 M3 `$ K
  49.                 /* For testing4 E7 ?, I6 E) B' q- A+ _5 h+ ~
  50.                 for(i=0;i<streamLength;i++) {7 z; M# Z! {+ ?2 z# Y; t
  51.                         cout << buffer[i];: K# p. n+ f  G
  52.                 }+ a7 x- m; V% D  R0 l0 `4 ~! _! Z: s
  53.                 */0 t: K7 y( H  l4 h- ?/ v) i6 }
  54.                 }
    ) ]6 u2 ^- u9 s9 a3 G) j
  55.         else {, h3 `% L: m1 ?1 B
  56.         cout << "Failed to read file." << endl;
    , a6 e7 M8 G; G, Q& W9 t% B/ \
  57.         return -1;
    ) t& \7 y3 x  y( i* p! a
  58.         }; [% ~& o3 P+ U" r+ r6 U; Z
  59.         & e% N5 |; X; b1 c5 ?  T: X% B+ b
  60.         string processStr (buffer);
    ! ~4 E, P( M- C& Z2 g
  61.         delete [] buffer;% }9 M6 [; E3 j" w- A& ]
  62.         0 S, `( }* p, q! h7 k
  63.         // DUMB DUMB DUMB....# ?7 n$ n8 }9 Z% H$ s$ h
  64.         ; p+ n( j$ G$ ?5 `( l% a  Z4 k* Q
  65.         int nextSearchPos = 0;) f. r' |  ?" O# z
  66.         int tmpSearchPos[2] = {0};7 ?, q: E0 N  f: d" Q/ W
  67.         int entriesCount = 0;
    4 T: i: Q8 X4 J  }3 h  Q
  68.        
    $ \, c# z5 S3 R8 x7 F7 T0 A( ~
  69.         : N! E- _+ w. w& {- ]+ s( f, T
  70.        
    3 P1 N# _  ?1 J8 P' H$ O: w! x
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    8 E. [' U( Y- Y! ^
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;5 W) M! N7 I6 a  W) {4 W
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    5 D3 Q/ F# f0 |! u; X1 V
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);% y8 E( q7 _4 J9 t" y& @
  75.                
    % u! @1 J; g' i" L$ g
  76.                 if(tmpSearchPos[0]!=string::npos) {
    + S; h. x3 f& e, [& W9 K
  77.                         i=tmpSearchPos[0]+11;
    * c1 J  e4 |* M' @' v2 u, d
  78.                        
    - @8 o9 _5 F" F4 S; b
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    7 W- ]: W# M: N4 r6 U4 W( ?
  80.                         cout << processStr[i];
    5 O* E" D* E7 @( @7 o6 r' z
  81.                         i++;
    + p% k! x% V; u/ f8 U8 e% r
  82.                         }9 N! S  q% g1 r
  83.                        
    2 q* W4 @( [/ X3 v/ R
  84.                         cout << endl;
    4 |' ]# E! b4 ^5 `) M
  85.                        
    # S( I1 I% A, Y3 ?
  86.                 }
    ' j9 D; Z% L6 d2 J" d, o& R
  87.                
    0 h- w( D4 d* b# p
  88.                 if(tmpSearchPos[1]!=string::npos) {
    1 G9 t+ F2 Z' \: n. u" [9 E' |
  89.                         i=tmpSearchPos[1]+13;' S% G: U# q) t& a) ^) q4 B; B* T# m2 P
  90.                        
    2 G3 n6 ?8 r( U+ D) O* b- f6 _
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    4 {( ^( H0 f5 t; k5 O: ?2 E
  92.                         cout << processStr[i];; L9 H% x5 F: _! d- ^3 z
  93.                         i++;, n, t" n! L& L) T. C9 B
  94.                         }
      F2 w) F! q1 x! s
  95.                         , Q! l8 S0 \( Q" ]3 w( C; f
  96.                         cout << endl;
    # Q( f9 s- B9 x5 A% q$ Y
  97.                        
    7 B/ |, P7 ]9 Y0 C% X3 ~
  98.                 }
    + J) X5 W4 a* I' _0 O1 S( S" _
  99.                 6 I5 p& I# J' f, I
  100.                 entriesCount++;8 h9 e7 G& \4 L- X
  101.         }0 ?. ]; s' d8 G- F) I  e" S% p6 v* Y
  102.        
    . R$ C# J: R, s! f
  103.         cout<<entriesCount;
    6 y- Y9 k0 i8 [) R. W; h9 }
  104.         return 0;) v% X# L0 ]) M& Y' }. D
  105.        
    6 Z: a1 `0 T- i
  106. }
复制代码
Update: 最后一行输出条目数., _0 T7 F, p' d0 _6 a

- o4 T" ?5 T. D% z+ h6 E8 L( \& `* {[ 本帖最后由 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 太空游戏站