Hi, I'm trying to copy from one string to another. But I have some problems with the code I guess.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void fun(char buffer[])
{
int i = 0,k = 0;
while(buffer[k] != ' ')
k += 1;
char* buff = newchar[k];
for(i = 0; i < k; i ++)
buff[i] = buffer[i];
cout<<strlen(buff);//14 instead of 4
puts(buff);
}
int main()
{
char buffer[12] = {"abcd dfd er"};
fun(buffer);
system("pause");
}
first of all if I try to do strlen(buff) I get 14 instead of 4, why is that?
and second when I do puts(buff) it prints me abcd and some random symbols.
how can I fix it?