Solved

exception error breaks too nomemory.cpp

Posted on 2004-04-17
4
228 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now