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
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.
#include <iostream>
#include <stdio.h>
#include <string.h>
usingnamespace 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...