Witam,
Męczę się już trochę czasu z poniższą funkcją i zastanawiam się czy wszystko z nią okej ponieważ program wysypuje się.
char * read(int x, int y, char * tekst)
{
COORD cor;
cor.X = x;
cor.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cor);
char *res = (char*)malloc((strlen(tekst)+1)*sizeof(char));
strcpy(res, tekst);
char key = 0;
while (key != '\r') {
if (key != 0 && key != '\b') {
putchar(key);
int len = strlen(res) + 1;
res = (char*)realloc(res, sizeof(char)*len);
memset(res + len, '\0', 1);
memset(res + len - 1, key, 1);
}
else if (key == '\b' && strlen(res)) {
printf("\b \b");
int len = strlen(res);
res = (char*)realloc(res, sizeof(char)*len);
memset(res + len - 1, '\0', 1);
}
key = _getch();
}
free(tekst);
return res;
}
int main()
{
char * p = (char*)malloc(15*sizeof(char));
strcpy(p, "Jakis tekst");
p = read(x, y, p);
}
Proszę o pomoc!
Z góry dziękuje :)