Solved

exception error breaks too nomemory.cpp

Posted on 2004-04-17
4
230 Views
Last Modified: 2011-09-20
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
Comment
Question by:Rackboy
4 Comments
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 50 total points
ID: 10851894
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10852783
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
 
LVL 2

Expert Comment

by:sin_
ID: 10877076
do you have any stacktrace?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question