I have this line of code in my program which works fine except that the memory utilization is high I need to convert all parts to dynamic allocation but i have error at this line strcpy_s(p,sizeof(p), line.c_str());
the original code is :
ifstream inFile1, inFile2;
string pattern,text,line;
cout<<"Enter file name.\n";
cin>>pattern;
inFile1.open(pattern.c_str());
if ( !inFile1 )
{
cout<<"Unable to open file. Enter a different name: ";
inFile1.clear();
cin >> pattern;
inFile1.open(pattern.c_str());
}
char *p;
p = new char[500];
while(getline(inFile1, line))
{
strcpy_s(p, 500, line.c_str());
cout<<p;
}
the modified code with errors :
Read the pattern file
while(getline(inFile1, line))
{
char* p = NULL;
p = new char[sizeof(line)];
cout<< line.length().
strcpy_s(p,sizeof(p), line.c_str());
cout<<p;