-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
102 lines (91 loc) · 1.59 KB
/
Source.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
using namespace std;
int str_len(char a[]) // chieu dai String
{
int i;
for (i = 0; a[i] != 0; i++)
{
}
return i;
}
void strCopy(char dest[], char src[]) // Copy String
{
int i;
for (i = 0; src[i] != 0; i++)
{
dest[i] = src[i];
}
dest[i] = 0; // tranh string co ki tu IIII
}
bool strCmp(char a[], char b[]) // So sanh String
{
int i;
for (i = 0; a[i] != 0 && b[i] != 0; i++)
{
if (a[i] != b[i]) return false;
}
if (a[i] != 0) return false;
if (b[i] != 0) return false;
return true;
}
void rev(char dest[] , char src[]) // Dao nguoc String
{
int len = str_len(src);
int j = 0;
for (int i = len - 1; i >= 0; i--)
{
dest[j] = src[i];
j++;
}
dest[j] = 0;
}
int atoi(char a[]) // Chuoi sang so
{
int number = 0 ;
char c = '9';
for (int i = 0; a[i] != 0; i++)
{
int n = a[i] - '0';
number = number * 10 + n;
}
return number;
}
void itoa(int number , char dest[]) // So sang chuoi
{
char src[20];
int i = 0;
while (number > 0)
{
int a = number % 10;
src[i] = a + '0';
i++;
number /= 10;
}
src[i] = 0;
rev(dest, src);
}
int main()
{
char a[20] = "Hello World";
char b[20];
strCopy(b, a);
cout << int('a') << endl;
char c[20] = "Hello World";
if (strCmp(a, c))
{
cout << "Giong nhau" <<endl;
}
else {
cout << "Khac nhau" << endl;
}
char d[20] ="";
rev(d, a);
cout << d << endl;
char e[20] = "123";
cout << atoi(e) + 100 << endl;
int f = 532;
char h[20];
itoa(f,h);
cout << h;
return 0;
}