Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

exception error breaks too nomemory.cpp

Posted on 2004-04-17
4
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

664 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