The problem is: pattern is an uninitialized pointer. Because it is uninitialized, the value is random; because it is a pointer, it is thus randomly points to any memory location – including your program code area, data area, or system area. Program crashes is the least you would expect.
You have to initialize the pointer to a allocated memory:
Code:
char *pattern = new char[2]; // you need one more space for the ‘\0’ character
strcpy(pattern, "\t"); // char[0] is ‘\t’, char[1] is ‘\0’
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.