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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis& p/ ^0 q' ~! n$ s3 n) d. ?

  2. 4 I/ Y& a4 B* d- C
  3. //
    8 q* h' T0 b: ?* G$ x/ e
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    - F  i4 G; }2 A) a% K5 G  l9 ]
  5. // In case this is not legally possible,
    # ^! g- r# \: R, ]' G6 x8 a
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law./ o3 M  Y' X5 J( \
  7. //
    0 q  `8 ]# q5 X, Q

  8. & d2 u- @& P, i% Z8 w3 ?
  9. #include <iostream>6 h+ H6 I- r/ L3 I. J% n
  10. #include <fstream>
    2 V7 x1 A  N# f1 _& U
  11. #include <cctype>
    . o/ Q& @0 r, _3 `9 ?/ p
  12. using namespace std;
    $ N5 W  T% q/ ^, X' y( R
  13. 9 I# a- d( G4 |  @8 j+ V
  14. // MACROS
    , o9 F! z" c, f
  15. #define SYSTEM_BLOCK_STR "[system]"
    ; w7 J; L/ h6 R
  16. #define NICKNAME_STR "nickname = "
    4 }2 T- p3 W+ M7 o
  17. #define IDS_STR "strid_name = "* t, r. u1 Z. ^1 [
  18. //
    4 }1 c. b" U7 w2 m# U5 Y" y
  19. 9 q, ]1 e; {. G4 \0 s  _
  20. ifstream inf;
    * R1 K" w/ f& d3 |
  21. char *buffer;6 ?' x0 w4 X6 U0 B( C
  22.   Y, {% }( Q) J' H
  23. int main(int argc, char *argv[])' l& X' Q6 x( p. C8 [/ |
  24. {
    ! B) J" E0 U6 ?( R& U- B
  25.         int i;
    1 x: B' m/ R6 j& h1 }/ p* F( U
  26.        
    8 H: m( e0 C; o: \
  27.         if(argc!=2){ , L! }! e1 m, h  Q6 g0 e' w
  28.                 cout << "This program requires one and only one argument.";
    / S( ?/ A, S- p5 b0 t3 F: n
  29.                 return -1;3 a5 j( \5 s! T0 \) I
  30.                 }, g- Z7 G# p! r7 u0 a
  31.        
    ; w" C, a* i  s: |* S8 b9 C$ O. w
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);5 j' C  M  J- z
  33.         if(!inf) {+ l$ I1 ?. I! G, f
  34.                 cout << "Error opening file.";
    1 B: C6 J$ ^6 H5 `, m! I
  35.                 return -1;. v- O" Y# E3 k7 f: ^
  36.                 }
    ! F$ |7 @5 v. j+ o) _
  37.                 3 x2 ^) g6 k% i  l- Q
  38.         int streamLength = inf.tellg();+ c, P- L, I9 U7 a; ?% d
  39.         if(streamLength!=-1) {
    3 P* w* w7 b+ s4 h/ Z2 ~2 j
  40.                 inf.seekg(0, ios::beg);+ A; @$ u, l# @, k: n( _1 ]
  41.                
    " @5 O$ |. |2 u& R2 G' S% I0 Q
  42.                 buffer = new char [streamLength];
    ) `* }7 ?$ _( _6 f, \6 {8 ?# O
  43.                 // Read file;
    $ E; ]9 w' L; t1 q2 N
  44.                 for(i=0;i<streamLength;i++) {0 V- T5 X. ~( F! w9 e! }7 o/ {
  45.                         inf.get(buffer[i]);7 i+ f/ R5 Z7 f5 U2 q2 o9 C1 ~- b
  46.                         buffer[i] = tolower(buffer[i]);
      s( h4 v  s# j
  47.                         }& d0 s1 U" N. h: s( E, ^
  48.                
    * o4 `/ p" u. F: h8 W, }
  49.                 /* For testing2 x7 |% K' D& t& u+ _( T
  50.                 for(i=0;i<streamLength;i++) {# b4 L2 c! N# _
  51.                         cout << buffer[i];
    $ Z. W3 j! q* Z! A
  52.                 }/ f+ [# x& }6 `4 {" a  r/ ]; J
  53.                 */
    9 W5 ]5 f$ Q6 y9 o' N# d
  54.                 }: [' B! i) g, C" M  ~$ X' c
  55.         else {8 i8 @" n! Q+ l7 W( ~
  56.         cout << "Failed to read file." << endl;$ F) O, |7 H) u# _! u0 B- |
  57.         return -1;* W6 A; W6 D/ C8 X
  58.         }% q6 K8 D/ ?$ x6 Y0 a% Y
  59.         4 D8 l) F( i/ r2 ~
  60.         string processStr (buffer);
    , Y. o/ @8 p- [: L
  61.         delete [] buffer;
    ) V+ V5 O) d9 H$ |+ H
  62.         . G: P2 m2 X8 s- P" ~
  63.         // DUMB DUMB DUMB....
    " K" ?# c1 y" o, I& q# |$ G9 i
  64.        
    8 ~% U! o  V4 ]' U4 P  L4 D
  65.         int nextSearchPos = 0;9 a  q; i# k  {1 P2 P( _) D
  66.         int tmpSearchPos[2] = {0};* {% p" E* j! H* h
  67.         int entriesCount = 0;0 X1 F, v5 _' S  D' @
  68.         , ^8 |3 @* g5 {# c: U
  69.         1 |/ C( [+ m8 O, g9 K7 o
  70.         + D6 a8 q# A- @) o
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {" H- [, a3 G# P( R, i
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    + _$ \( Q7 z! F  [, e
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    $ ^/ x# s, ~1 w% F
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);! m% L' ~% o, }
  75.                 # [+ `& p" p% b7 s, y( f
  76.                 if(tmpSearchPos[0]!=string::npos) {
    $ x( E+ B& @3 ^3 @. S2 q: W
  77.                         i=tmpSearchPos[0]+11;
    + F2 ], a0 y9 S9 t. c5 m2 f6 Q' X
  78.                        
    7 `7 e9 v+ G/ H3 t2 f4 K4 F
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {$ F- f* @+ O+ ?% @8 U; m
  80.                         cout << processStr[i];
    - G! H$ ]6 N+ x6 D
  81.                         i++;
    5 T$ H' z% t6 J1 A
  82.                         }
    " l- Q$ M- U  a' ?8 R$ l6 }
  83.                        
    . h! q1 K# g9 H
  84.                         cout << endl;
    ' j: E; z4 j- q/ x3 u& @
  85.                        
    4 B' m) Y6 r) M- K! v, g
  86.                 }
    ( C+ I2 M, t/ f. P' p" C9 V6 V
  87.                 . X/ B' G2 q( F# [
  88.                 if(tmpSearchPos[1]!=string::npos) {
    3 h) _# m0 g; d9 a
  89.                         i=tmpSearchPos[1]+13;  ?, j! |+ C- q
  90.                        
    4 U7 \0 j% E+ A
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {; m8 G# M& J3 J2 B" C# o
  92.                         cout << processStr[i];5 E9 K7 Z. i* @9 g3 n- P7 Y# o
  93.                         i++;
    ! z4 V+ D5 j* e& Y; d0 ]  ^
  94.                         }" L5 s  {( q; X# m* P( N
  95.                         2 y! R: f3 e" l1 j, U
  96.                         cout << endl;4 Q; q5 K/ F! X- t
  97.                         - ?0 v7 F2 ~/ A5 r# H
  98.                 }: y) y% `  x% [  e" ~, g* ~& h3 `
  99.                
    9 }# ?4 C- m5 W/ }7 [
  100.                 entriesCount++;: d" y2 w0 U# W5 k1 y* w+ v
  101.         }
    4 W0 a' O' F9 M1 Y
  102.        
    6 H9 E$ ^8 @$ H0 w* C
  103.         cout<<entriesCount;
    - L# r( z' C( ^) ^9 \* S9 I7 V# I
  104.         return 0;3 H/ a2 U; f  t  ^6 ]
  105.         ( F$ Z9 ?1 m. B3 t# H
  106. }
复制代码
Update: 最后一行输出条目数.- w" H# C# y: y4 C
' A7 i! @1 p$ U  G: G) F
[ 本帖最后由 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 太空游戏站