May 9, 2014 at 4:17pm
You have 3 v's so the output will be: 3e3v.
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
|
#include <iostream>
#include <cstring>
using namespace std;
char chaf(char *ch)
{
char* start = ch; // need to remember where the string starts
int n = 0;
char str[20];
char s = *ch;
int lengh = 0;
while (*ch != '\0')
{
while (*ch == s) // changed assignment to equality test
{
lengh++;
ch++;
}
str[n++] = lengh + '0';
str[n++] = s;
s = *ch;
lengh = 0;
}
// ch = &str[0]; // copy is incorrect
memcpy(start, str, n); // copy result over input
start[n] = 0; // terminate the string
return *ch; // not needed
}
main()
{
char x[] = {'e','e','e','v','v','v','\0'};
// chaf(0); // Need to pass in x
chaf(x);
cout << x;
return 0;
}
|
Last edited on May 9, 2014 at 4:18pm