strcmp와 strlen을 구현

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// STRFUNC.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
 
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
int mystrlen(char* txt)
{
    int count = 0;
 
    while( *(unsigned char *) txt)
    { 
        ++txt;
        ++count; 
    }
 
    return count;
}
 
int mymystrcmp(const char *src, const char *dest)
{
  int ret = 0;
  while (!(ret = *(unsigned char *) src - *(unsigned char *) dest) && *dest) 
  { 
      ++src, ++dest; 
  }
 
  if (ret < 0)
    ret = -1;
  else if (ret > 0)
    ret = 1 ;
 
  return ret;
}
 
 
class CLASSA
{
public:
    int a;
};
 
int _tmain(int argc, _TCHAR* argv[])
{
    char* txt0 = "1234abcaABCD";
    char* txt1 = "1234abcaABCD";
    char* txt2 = "1234abcf";
    char* txt3 = "1234,abcd,ABCD ";
    char* txt4 = "1234abcaABCDc";
 
    const int a = 0;
 
    int max = strlen(txt0);
    cout << max << endl;
    max = mystrlen(txt0);
    cout << max << endl;
 
    int cmp = strcmp(txt0, txt1);
    cout << "같다 " << cmp << endl;
    cmp = strcmp(txt0, txt2);
    cout << "짧다 " << cmp << endl;
    cmp = strcmp(txt0, txt3);
    cout << "길다 " << cmp << endl;
    cmp = strcmp(txt0, txt4);
    cout << "길이는 같다 " << cmp << endl;
 
    cmp = mymystrcmp(txt0, txt1); 
    cout << "같다 " << cmp << endl; 
    cmp = mymystrcmp(txt0, txt2); 
    cout << "짧다 " << cmp << endl;
    cmp = mymystrcmp(txt0, txt3); 
    cout << "길다 " << cmp << endl;
    cmp = mymystrcmp(txt0, txt4); 
    cout << "길이는 같다 " << cmp << endl;
 
    return 0;
}
 
 


'게임개발공부 > 직접 구현해 보겠습니다' 카테고리의 다른 글

sqrt 제곱근 구하기.  (0) 2014.07.10
Posted by JJOREG