i am still preparing for an c++ test and i am trying to convert a c-string to a byte-count-string.
so if i have a string like:
"Hello"
I have to convert it to:
"5Hello"
However the problem i am facing is that i can't convert the calculated count of the string to an char value.
it should be very straight forward since this excercise gives only very little points in the test
#include "stdafx.h"
#include "iostream";
using namespace std;
char* c2b(char* bc)
{
int b = strlen(bc) +1;
char* temp = new char;
int i;
for(i = 1; i < b; i++)
temp = bc[i-1];
b -= 1;
char test = static_cast<char>(b); //I want to cast the Integer to a char
temp[0] = test;
//temp = '\0'; //Not needed for the Byte-Count-String
bc = temp;
return bc;
}
int _tmain(int argc, _TCHAR* argv[])
{
char bc[] = "String";
cout << c2b(bc);
char f;
cin >> f;
return 0;
}