program not returning zero

hello friends...
my c++ program code is

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

void copy(char *name, char *dumy)
{
int i = 0;
while(i < strlen(name) )
{
*(dumy+i) = *(name+i);
i++;
}
*(dumy+i) = '\0';
}

int main()
{
char *name, *dumy;
cout << "enter a string ";
gets(name);
dumy = new char(strlen(name) + 1);
cout << "String is copied in dumy = ";
copy(name, dumy);
cout << dumy;

return 0;
}

this program running correctly doing copy to DUMY but it is not terminating with status ZERO. I am not getting what is the error. <br/><br/>
PLATEFORM : codeb::locks 10.05 with GNU GCC compiler on windows XP. & is i want to get suggestion from experienced programmers that is this ide(code::blocks) is good to use at more than beginners stage. Thanks


dumy = new char(strlen(name) + 1); ¿why did you do that?
Good morning

If you are programmin with C++ it's better to avoid char components and use string, string is more generic and more usefull and in general you don't have so many problems.

so, a bit example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
string name, dumy;
cout << "enter a string ";
//gets(name); this function is C
cin >> name; // cin is C++

cout << "String is copied in dumy = ";
dumy = name;
cout << dumy;

return 0;
}

thanks you all... and ""dumy = new char(strlen(name) + 1);"" was to dynamically allocate memory to dumy with one more space than the length of name(for null character at the end).
i guess that was just a waste there to add in program. thanks again...
The thing is that you never allocated space for 'name'
i got it thanks
Topic archived. No new replies allowed.