How to convert string to char* and use function(char* text)

Oct 17, 2009 at 4:06pm
Hello.
I have problem.
Program works with code:

1
2
3
4
5
6
string nameF = "";
cin >> nameF;

char* nameFC = (char*)malloc( sizeof( char ) *(nameF.length() +1) );
strcpy(nameFC, nameF.c_str());
cout << "char* == " << nameFC << endl;


but if i want to use function whose i write
1
2
3
4
5
6
7
8
char* nameFC = (char*)malloc( sizeof( char ) *(nameF.length() +1) );
strcpy(nameFC, nameF.c_str());
cout << "char* == " << nameFC << endl;

//my funciton(char* text)
//my function work good if i use 
// char* nameFC = "text";
setText(nameFC);


i have error
warning C4996: 'strcpy': This function or variable may be unsafe.
Last edited on Oct 17, 2009 at 4:17pm
Oct 17, 2009 at 4:08pm
Oct 17, 2009 at 4:11pm
I have used before strncpy(), but i have this same error.
Oct 17, 2009 at 4:36pm
Oct 17, 2009 at 6:44pm
C4996 can always be safely ignored.
#pragma warning(disable:4996)
Topic archived. No new replies allowed.