What exacty you code do :
+----------------------------------------------+
| +--------------------------------------+ |
| txt|*txt |*txt+1 |*txt+2 |*txt+3 |*txt+4 | |
| +--------------------------------------+ |
| ^ ^ no memory alloc ^ |
| | |_______not used_______| |
| +----+ |
|*txt |____| <------------------------------+---you never give a value here,
| +1 |____| <--j |
| +2 |____| <-- '\n' |
| +3 |____| <--s |
| +4 |____| <-- '\n' |
| . . |
| . . |
| . ____ |
| +19 |____| |
+----------------------------------------------+
So you need :
- re-write you while loop and deal with the
'\n'
- when user type q , alloc new string memory and collect user input .
Suggust:
In you fisrt string
Use txt[0]
instead of *txt
, use txt[0][i] and i++
instead of **txt and (*txt)++
.
Hope can help. :-)