Hi,
so i wrote a few of the programs on my own after all the help previosuly but i've got stuck in this one here. The point is the make the string alteast 'n' characters long by padding spaces to its right.
#include <iostream>
using namespace std;
void padRight(char *&a, int n)
{
int diff = strlen(a) - n;
if(diff >= 0)
{
return;
}
else
{
char *temp = a;
//cout << temp << endl;
a = (char *)malloc(n);
memset(a,' ',n);
while (*a++ = *temp++);
//cout << a << endl;
}
}
int main()
{
char p[] = "smiths";
cout << "before padding " << strlen(p) << " " << p << endl;
char *a = p;
padRight(a,10);
cout << "after padding " << strlen(a) << " " << a << endl;
};
output:
>
before padding 6 smiths
after padding 10 _MONETm
Please point me to the errors with explanations.