Now I have a function const char *get_string(size_t maxlen) where the significant part according to this problem is like
Code:
vector<char> str;
...
char *s = new char[str.size()+1];
/* Copy the vector to passed string */
for(size_t i = 0; i < str.size(); i++)
s[i] = str[i];
s[str.size()] = '\0';
str.clear();
return s;
in main() I have
Code:
char *s;
strcpy(s, get_string(4));
printf("\n%s", s);
There must be something wrong in the upper code 'cause if, in main(), I set s to NULL nothing seems to happen. What's going on?