-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicfunctionalities.h
More file actions
178 lines (150 loc) · 4.44 KB
/
Copy pathbasicfunctionalities.h
File metadata and controls
178 lines (150 loc) · 4.44 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<windows.h>
using namespace std;
int sizeofstring(char []);
bool stringcomparison(char [], char []);
void trim(char[]);
bool itisspace(char);
bool isnumber(const char input[]);
void copychararray(char [],const char []);
void logactivity(const char*);
char* readFileDynamic(const char*);
int getLongestLineLength(const char*);
char* allocateBufferForLongestLine(const char*);
void copychararray(char dest[], const char src[]) {
int i = 0;
while (src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0'; // Null-terminate the destination array
}
bool isnumber(const char input[]) {
int i = 0;
while (input[i] != '\0') {
if (!isdigit(input[i])) {
return false;
}
i++;
}
return i > 0;
}
void trim(char str[50]) {
int start = 0, end = 0;
//YE CHECK KARE GAA JB TK STARTING MAII SPACES NAA KITNAA CHARACTER LIYAA HAIN
while (str[start] != '\0' && itisspace(str[start])) {
start++;
}
end = start;
while (str[end] != '\0') {
end++;
}
end--;
//AB YEE END SAA CHECK KARNAA SHURU KARE GAA KAA END SAA KITNI SPACES HAIN
while (end >= start && itisspace(str[end])) {
end--;
}
int j = 0;
for (int i = start; i <= end; i++) {
str[j++] = str[i];
}
str[j] = '\0';
}
bool itisspace(char x) {
if (x == ' ') {
return true;
}
return false;
}
int sizeofstring(char tobechecked[50]){
int count=0;
for(int i=0;tobechecked[i]!='\0';i++){
count++;
}
return count;
}
bool stringcomparison(char string1[100], char string2[100]){
int length1 = sizeofstring(string1);
int length2 = sizeofstring(string2);
if(length1!=length2){
return false;
}
for(int i=0; i<length1;i++){
if(string1[i]!=string2[i]){
return false;
}
}
return true;
}
void logactivity(const char* action) {
ofstream file("ActivityLogs.txt", ios::app);
time_t now = time(0);
tm* localTime = localtime(&now);
char date[11];
sprintf(date, "%02d/%02d/%04d", localTime->tm_mday, localTime->tm_mon + 1, localTime->tm_year + 1900);
char time[9];
sprintf(time, "%02d:%02d:%02d", localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
file << action << " | " << date << " | " << time << endl;
file.close(); // Close the file
}
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole != INVALID_HANDLE_VALUE) {
SetConsoleTextAttribute(hConsole, color);
}
}
void resetColor() {
setColor(7); // 7 is the default console color (white text on black background)
}
void caesarCipherEncrypt(char text[], int shift) {
for (int i = 0; text[i] != '\0'; i++) {
char ch = text[i];
if (ch >= 'A' && ch <= 'Z') { // Uppercase letters
text[i] = ((ch - 'A' + shift) % 26) + 'A';
} else if (ch >= 'a' && ch <= 'z') { // Lowercase letters
text[i] = ((ch - 'a' + shift) % 26) + 'a';
} else if (ch >= '0' && ch <= '9') { // Numbers
text[i] = ((ch - '0' + shift) % 10) + '0';
}
}
}
void caesarCipherDecrypt(char text[], int shift) {
for (int i = 0; text[i] != '\0'; i++) {
char ch = text[i];
if (ch >= 'A' && ch <= 'Z') { // Uppercase letters
text[i] = ((ch - 'A' - shift + 26) % 26) + 'A';
} else if (ch >= 'a' && ch <= 'z') { // Lowercase letters
text[i] = ((ch - 'a' - shift + 26) % 26) + 'a';
} else if (ch >= '0' && ch <= '9') { // Numbers
text[i] = ((ch - '0' - shift + 10) % 10) + '0';
}
}
}
int getLongestLineLength(const char* filename) {
ifstream file(filename);
if (!file.is_open()) {
cout << "Error: Unable to open file.\n";
return -1;
}
char buffer[200];
int longestLineLength = 0;
while (file.getline(buffer, 200)) {
int currentLineLength = strlen(buffer);
if (currentLineLength > longestLineLength) {
longestLineLength = currentLineLength;
}
}
file.close();
return longestLineLength;
}
char* allocateBufferForLongestLine(const char* filename) {
int longestLineLength = getLongestLineLength(filename);
if (longestLineLength == -1) {
return nullptr;
}
char* buffer = new char[longestLineLength + 1]; // +1 for null-terminator
return buffer;
}