-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUntitled3.cpp
More file actions
45 lines (37 loc) · 899 Bytes
/
Copy pathUntitled3.cpp
File metadata and controls
45 lines (37 loc) · 899 Bytes
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
#include <iostream>
#include <cstring>
using namespace std;
char * myFunc(char src[])
{
for (int i = 0; i < strlen(src); i++) {
if ((src[i] < 'a') || (src[i] > 'z')) {
cout << "Bad input!!!" << endl;
return NULL;
}
}
char * result = new char( strlen(src) + 1);
// additional one char allocated for the end of string character '\0'
if (result == NULL) {
cout << "Memory allocation failure." << endl;
return NULL;
}
strcpy(result, src);
int i, j;
int delta = 'A' - 'a';
for(i = 0, j = 2*strlen(src); i < strlen(src); i++) {
result[j++] = src[i] + delta;
}
result[j] = '\0'; // insert the final '\0'
return result;
}
int main()
{
char src[3] ={'a','b','c'};
char * src2[];
src2[] = myFunc(src);
for(int i=0 ; i<3 ;i++)
{
cout<<*src2;
src2++;
}
}