8 Einträge, 1 Seite |
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
#include <iostream>
using namespace std;
int cstrlen(const char *text){
int laenge = 0;
while(*text++){
laenge++;
}
return laenge;
}
const char* cReverse(const char *text){
const char *tmpString;
int stringLaenge = cstrlen(text);
stringLaenge--;
int j = 0;
for(int i = stringLaenge; i >= 0; i--){
tmpString[j] = text[i];
j++;
}
return tmpString;
}
int main(){
const char *string = "Hugo ist blau";
int lang = cstrlen(string);
const char *test = cReverse(string);
cout<<"Der String ist "<<lang<<" Zeichen lang.\n";
cout<<test[0];
return 1;
}
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
namespace sk
{
int strlen(char* text)
{
int len = 0;
while(*text++) len++;
return len;
}
void swap(char & a, char & b)
{
char tmp = a;
a = b;
b = tmp;
}
const char* reverse(const char* text)
{
int len = sk::strlen(text)+1;
for(int i = 0; i < len/2; i++)
{
sk::swap(text[i], text[len-i-1]);
}
return text;
}
}
1
2
3
4
5
6
7
8
9
const char* reverse(char* text)
{
int len = sk::strlen(text);
for(int i = 0; i < len/2; i++)
{
sk::swap(text[i], text[len-i-1]);
}
return text;
}
8 Einträge, 1 Seite |