I am running through some basic tutorials on C, using Code::Blocks. Can anyone help me out with the following code, with some explanation? It builds but crashes when run.
The destination field blank is too small. Given that it is only one byte long, it has just enough room to store the null terminator, that is, a zero length string.
Attempting to do any string operation with a 1-byte field as the destination is bound to fail.
Also, rather than using the = operator here: aster="*"; you need the strcpy() function. Or just declare char aster[] = "*";
I think line should probably be the destination of your strcat operation.
Thanks Chervil. You were spot on with the blank pointer allocated length being too long, changed it for MAX_LEN+1.
I also encountered a problem when inserting "" into the pointers target as I now know this eliminates/overwrites the pointer address. I got around this by using blank[0]=0;
It compiled and worked following that. I didn't adjust aster. Its an early tutorial program, strcpy is upcoming so I will review that once I read through it.