I have created a function in C that validates the user input for string. I'm trying to figure out how to convert it in C++. I don't know if some of the functions that I've used right here is allowed to be used in C++.
Code:char *getString( int strSize )
{
char value;//, arrValue[ strSize ];
char *str;
char *rcvValue;
int ctr = 0;
//rcvValue = arrValue;
rcvValue = malloc( 5 * sizeof( strSize ) );
while( 1 )
{
value = getch();
if( value == '\b' && ctr > 0 )
{
putch( value );
putch( ' ' );
putch( value );
ctr--;
}
else if( value != '\b' && value != '\r' && ctr != 30 )
{
if( isspace( value ) || isalpha( value ) )
{
//arrValue[ ctr ] = value;
rcvValue[ ctr ] = value;
putch( value );
ctr++;
}
}
if( value == '\r' )
{
if( ctr > 0 )
break;
}
}
rcvValue[ ctr ] = '\0';
//arrValue[ ctr ] = '\0';
//rcvValue = malloc( strlen( arrValue ) + 1 );
return rcvValue;
}