I think I got it, but before I post the finished product I will post 7stud's exercise just in case anyone else is having the same problem I had.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char data[] = "hello world";
char * pointerw = strstr (data, "w");
char * pointerh = strstr (data, "h");
char * pointerd = strstr (data, "d");
char * newdata;
char * newdataTwo;
int wh = pointerw - pointerh;
newdata = new char [wh];
for (int i = 0; i < wh; i++)
{
newdata[i] = data[i];
}
cout << newdata << endl;
cout << wh << endl;
int dw = pointerd - pointerw;
cout << dw << endl;
int dh = dw + wh;
cout << dh << endl;
newdataTwo = new char [dh];
for (int a = 0; a < dh + 1; a++)
{
newdataTwo[a] = data[a];
}
cout << newdataTwo << endl;
return 0;
}
Here is the finished product:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char needle[] = "// -->";
char fileNew[] = "newhtml.htm";
char fileRead[256];
int bufferlength;
char * haystack;
char * toCopy;
cout << "enter name of the html file to open and edit: ";
cin.getline(fileRead, 256);
ifstream inputFile(fileRead);
inputFile.seekg (0, ios::end);
bufferlength = inputFile.tellg();
inputFile.seekg (0, ios::beg);
haystack = new char [bufferlength];
ofstream outputFile(fileNew);
inputFile.getline(haystack, bufferlength, '¥');
char * pointer1 = strstr (haystack, needle);
char * pointer2 = strstr (haystack, "<");
int counter = pointer1 - pointer2;
toCopy = new char [counter];
for (int i = 0; i < counter - 2; i++)
{
toCopy[i] = haystack[i];
}
outputFile << toCopy;
outputFile << "\n index = 0; \n for (i = 0; i < ansMap.length; ++i) { document.write (TranslateAnswer (ansMap[i], i)); \n } \n // --> \n </script></head></html>";
cout << "Open newhtml.htm in your favorite webbrowser and enjoy\n";
return 0;
}