This function is supposed to read and expand my array (stringa) until the user hits enter, then expands also reverse
to the same size of stringa
.
But after 3 letters the program just stops
void inputStringaAndCreateReverse(char* *stringa, char* *reverse, int* iStringa) {
int inputChar, i = 0, size = 1;
bool notEnter = true;
printf("Insert the string: ");
while (notEnter) {
if ((inputChar = getche()) != '\r') {
*stringa[i] = inputChar;
i++;
*stringa = realloc(*stringa, (++size) * sizeof(char));
} else if (size != 1) {
notEnter = false;
system("CLS");
} else {
printf("\n");
}
}
*stringa[i] = '\0';
*iStringa = strlen(*stringa) - 1;
*reverse = realloc(*reverse, (*iStringa + 1) * sizeof(char));
}
These are the results of a test (I wanted to write hello)
hell
stringa and reverse are allocated in the main as
stringa = (char*) malloc(sizeof(char))