Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *getString()
- {
- int nSize = 2;
- char *str;
- str = (char *) malloc (nSize * sizeof(*str));
- str[1] = 0;
- int nIndex = 0;
- do
- {
- str[nIndex] = getch();
- printf("%c", str[nIndex]);
- nIndex++;
- if (nIndex == nSize)
- {
- char *strTmp;
- nSize += 1;
- strTmp = (char *) realloc (str, nSize * sizeof(*str));
- str = strTmp;
- str[nSize - 1] = 0;
- }
- }while (str[nIndex - 1] != 13);
- char *strTmp;
- strTmp = (char *) realloc (str, (nSize - 2) * sizeof(*str));
- str = strTmp;
- str[nSize - 2] = 0;
- return str;
- }
Add Comment
Please, Sign In to add comment