[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

exception error breaks too nomemory.cpp

I am getting a exception error and when I break it breaks into nomemory.cpp.  Do I need to clear my memory some how?  any idea what type of things could cause this? hear is my program if it helps

#include "Mstring.h"
#include <iostream>
#include <fstream>

using namespace std;

//Precondition: file is open pass int array[] for row and rowsize for
// array size. Search type is 1 for add 2 for Logg and 3 for Pass
//Postcondition: Will pass back an mstring object with searchType
// in it and \0 if not found
Mstring findStr(char rowIn[],int rowSize,int searchType);

//Precondtion: pass in open output file
//Postcondition: Will output html header to the file
void headerOut(ofstream& fout);

//Precondtion: pass in open output file
//Postcondition Will output html footer to the file
void footerOut(ofstream& fout);

//Precondtion: pass in open output file and address logg and pass
// as Mstrings objects
//Postcondition: will output the html link pass and logg
void addLink(ofstream& fout,Mstring addIn,Mstring passIn,Mstring loggIn);

//Precondition:pass in char array and the size
//Postcondition:will set all the spaces in the array to \0
void clearRow(char rowIn[],int Size);

int main()
{
      Mstring address;
      Mstring pass;
      Mstring logg;
      Mstring empty;
      
      int numrow(0);

      const int size(300);
      char fileName[200];
      char row[size];
      char htmlName[30] = "pornlinks.htm";

      cout << "Enter the name of the file you would like to edit: ";
      cin >> fileName;

      ifstream file;
      file.open(fileName);
      if(file.fail())
      {
            exit(1);
      }
      ofstream fileOut;
      fileOut.open("porn.html");
      if(fileOut.fail())
      {
            exit(1);
      }

      headerOut(fileOut);

      do
      {
            enum type {Address = 1,Pass = 2,Logg = 3};
            file.getline(row,401);
            address = findStr(row,size,Address);
            if(address != empty)
                  logg = findStr(row,size,Logg);
            if(address != empty)
                  pass = findStr(row,size,Pass);
            if(address != empty && pass != empty && logg != empty)
            {
                  addLink(fileOut,address,pass,logg);
                  address = empty;
                  pass = empty;
                  logg = empty;
                  clearRow(row,size);
            }
            numrow++;
            if(numrow == 525)
            {
                  int stop;

                  cout << "pause";
                  cin >> stop;
            }

      }while(!file.eof());
      if(!fileOut.fail())
      {
            footerOut(fileOut);
      }
      fileOut.close();
return 0;
}

//Will set all the chars in the row to \o
void clearRow(char rowIn[],int Size)
{
      for(int i = 0;i < Size;i++)
            rowIn[i] = '\0';
}


//Will output the header for the html file
void headerOut(ofstream& fout)
{
      fout << endl << "<html>";
      fout << endl << "<head>";
      fout << endl << "<title>I love Free Porn</title>";
      fout << endl << "</head>";
      fout << endl << "<body style=\"background-color: darkblue;\">";
      fout << endl << "<h1 align=\"center\" style=\"color: red;\">Dave\'s ****ing Porn Page</h1>";
      fout << endl << "<form name=\"porn\">";
      fout << endl << "<table>";
      fout << endl << "      <tr bgcolor=\"white\">";
            fout << endl << "      <td width=300 align=\"center\">";
                  fout << endl << "      <b>Address</b>";
            fout << endl << "      </td >";
            fout << endl << "      <td width=100 align=\"center\">";
                  fout << endl << "      <b>Logg</b>";
            fout << endl << "      </td>";
            fout << endl << "      <td width=100 align=\"center\">";
                  fout << endl << "      <b>Pass</b>";
            fout << endl << "      </td>";
            fout << endl <<"      </tr>";
}

void footerOut(ofstream& fout)
{
      fout << endl << "</form>";
      fout << endl << "</table>";
      fout << endl << "</body>";
      fout << endl << "</html>";
}

void addLink(ofstream& fout,Mstring addIn,Mstring passIn,Mstring loggIn)
{
fout << endl << "<tr bgcolor=\"white\">";
fout << endl << "            <td width=300 align=\"center\">";
fout << endl << "                  <a href=\"" << addIn << " \" target=\"_new\">" << addIn << "</a>";
fout << endl << "            </td >";
fout << endl << "            <td width=100 align=\"center\">";
fout << endl << "                  <input type=\"Textbox\" name=\"Logg\" value=\"" << passIn << " \"> ";
fout << endl << "            </td>";
fout << endl << "            <td width=100 align=\"center\">";
fout << endl << "                  <input type=\"Textbox\" name=\"Pass\" value=\" " << loggIn << " \"> ";
fout << endl << "            </td>";
fout << endl << "      </tr>";
}

Mstring findStr(char rowIn[],int rowSize,int searchType)
{      
      int searchLen(0);
      int searchStart(0);
      int searchEnd(0);
      char * charPtr;
      int i = 0;
      int j = 1;
      int k = 2;
      int l = 3;
      int z = 0;
      
      if (searchType == 1)
      {
            for (i,j,k,l;l < rowSize;i++,j++,k++,l++)
            {
                  
                  if (rowIn[i] == 'H' && rowIn[j] == 'T' && rowIn[k] == 'T' && rowIn[l] == 'P')
                  {
                        searchStart = i;
                  }
                  if(rowIn[i] == ' ' && rowIn[j] == 'L' && rowIn[k] == ':' )
                  {
                        searchEnd = l -4;
                  }
            }
      }
      else if(searchType == 2)
      {
            for (i,j,k,l;l < rowSize;i++,j++,k++,l++)
            {
                  
                  if (rowIn[i] == ' ' && rowIn[j] == 'L' && rowIn[k] == ':' )
                  {
                        searchStart = i + 6;
                  }
                  if(rowIn[i] == ' ' && rowIn[j] == 'P' && rowIn[k] == ':')
                  {
                        searchEnd = i - 1;
                  }
            }
      }
      else
      {
            for (i,j,k,l;l < rowSize;i++,j++,k++,l++)
            {
                  
                  if (rowIn[i] == ' ' && rowIn[j] == 'P' && rowIn[k] == ':')
                  {
                        searchStart = i + 6;
                  }
                   if(rowIn[i] == '\0')
                  {
                        searchEnd = i;
                  }
            }
      }

      searchLen = searchEnd - searchStart;
      charPtr = new char[searchLen+1];

      if (searchEnd != 0)
      {
            int count = 0;

            for(z = searchStart; z < searchEnd; z++ )
            {            
                  charPtr[count] = rowIn[z];
                  count++;
            }
            charPtr[searchLen] = '\0';
      }
      else
      {
            charPtr[0] = '\0';
      }

      Mstring Address(charPtr);
      
      return Address;
}
0
Rackboy
Asked:
Rackboy
1 Solution
 
lakshman_ceCommented:
Plz try do some exception handling to find out where the exception occurs.
You can refer to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_c.2b2b_.exception_examples.asp

-Lakshman
0
 
Karl Heinz KremerCommented:
Where does the error occur? Look at the stack after the crash, this will tell you how the function in nomemory.cpp was called. Which operating system are you using?
0
 
sin_Commented:
do you have any stacktrace?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now