Cardinal 0 Newbie Poster

HI,

My project is due tommorrow, I am stuck at this error which i have no clue. I have tried all my best to understand what is its cause but couldn't. I really need help.
All I am saying is if you can explain why its doing this.

***Problem***
We are trying to read processes, it sucessufully stores every process and its size and location. But what it dose is that when it reads the new process and i am trying to store every process using seprate objects[ object] of structure. It changes its name to the next process. e.g process[j] and process[j-1] and process[j-2] are getting the same names.
It deals with only function [ readFile & insert ].
I couldn't understand why?

***Project***
What projetc does is that we read all these processes enter them and exit them and do memory management through first-fit or worst-fit.

***input file***
e.g
Editor Enter 100
Enroll Enter 300
Scheduler Enter 100
Editor Exit 100

***Source Code****

#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>


#define TRUE  1
#define FALSE 0
#define ZERO  0
#define ONE   1
#define TWO   2
#define THREE 3
#define FOUR  4
#define FIVE  5

void readingArguments&#40; int argc, char *&#91;FIVE&#93; &#41;;
void readFile&#40; ifstream & &#41;;
void swapObject&#40; int j &#41;;
void swapBack&#40; int &#41;;
void insert&#40; char *, int &#41;;
void Delete&#40; char* &#41;;

int totalMemory;
int operatingSystem;
int firstFit;
int worstFit;
int i = 1;

struct memoryList&#123;
   int size;
   int location;
   char *name;
&#125; object&#91;100&#93;;

void main&#40; int argc, char * argv&#91;&#93; &#41;
&#123;
  
   cout << "\n" << endl;
   cout << "This is line number "  << __LINE__ <<  " of the file " 
        << __FILE__ << " which was compiled on "  << __DATE__
        << "\nat time " << __TIME__ << ".\n\n"; 

   readingArguments&#40; argc, argv &#41;;

&#125;

void readingArguments&#40; int argc, char * argv&#91;FIVE&#93; &#41;
&#123;

   if&#40; argc != FIVE &#41;
   &#123;
      cerr << "Usage &#58; a.out argv&#91;1&#93; argv&#91;2&#93; argv&#91;3&#93; argv&#91;4&#93; " << endl;
      exit&#40;1&#41;;
   &#125;

   ifstream inFile&#40; argv&#91;ONE&#93;, ios&#58;&#58;in &#41;;

   if&#40; !inFile &#41;
   &#123;
      cerr << "INPUT FILE CANNOT BE OPEN FOR INPUT" << endl;
      exit&#40;2&#41;;
   &#125;
   else
   &#123;
      cout << "INPUT FILE &#58; " << argv&#91;ONE&#93; << " OPEN FOR INPUT. \n " << endl;
   &#125;

   if&#40; atoi&#40;argv&#91;TWO&#93;&#41; == atoi&#40;"F"&#41; || atoi&#40;argv&#91;TWO&#93;&#41; == atoi&#40;"f"&#41; &#41;
   &#123;
      firstFit = TRUE;
      cout << "*** First-Fit Is Selected ***\n" << endl;
   &#125;
   else if &#40; atoi&#40;argv&#91;TWO&#93;&#41; == atoi&#40;"W"&#41; || atoi&#40;argv&#91;TWO&#93;&#41; == atoi&#40;"w"&#41; &#41;
   &#123;
      worstFit = TRUE;
      cout << "*** Worst-Fit Is Selected ***\n" << endl;
   &#125;
   else
   &#123;
      cout << " Usage argv&#91;2&#93; &#58; F for First-Fit or W for Worst-Fit " << endl;
      exit&#40;3&#41;;
   &#125;

   totalMemory = atoi&#40; argv&#91;THREE&#93; &#41;;
   operatingSystem = atoi&#40; argv&#91;FOUR&#93;&#41;;        

   readFile&#40; inFile &#41;;
&#125;


void readFile &#40; ifstream &inFile &#41;
&#123;
   
   char name&#91;40&#93;, Status&#91;17&#93;;
   char *status;
   char *enter = "Enter", *exit = "Exit";
   int memorySize, holder, cmp; 

   object&#91;1&#93;.name = "OS";
   object&#91;1&#93;.size = operatingSystem;
   object&#91;1&#93;.location = 0;

   for&#40; int k = 2; k < 10; k++ &#41;
      object&#91;k&#93;.name = "Hole"; 

   while &#40; inFile >> name >> Status >> memorySize &#41;
   &#123;
      status = Status;
      i++;
      cmp = strcmp&#40;status,enter&#41;;      
      if &#40; cmp == ZERO &#41;
        insert&#40; name, memorySize&#41;;
	cmp = strcmp&#40;status,exit&#41;;
     // if &#40; cmp == ZERO &#41;
       //  Delete &#40; name &#41;; 

	for&#40;int u = 1; u < 10; u++ &#41;
         cout << object&#91;u&#93;.name << " is loaded at address =  " << object&#91;u&#93;.location 
              << " with size = " << object&#91;u&#93;.size << "K\n" << endl;
	
   &#125;

   
&#125;

void insert&#40; char *Name, int size &#41;
&#123;
   int holder, cmp;
   char *hole = "Hole";
   char *holderName;

    for&#40; int j = 1; j < 10; j++ &#41;
    &#123; 
	holderName = object&#91;j&#93;.name;
      cmp = strcmp&#40;holderName,hole&#41;;
      cout << object&#91;j&#93;.name <<endl;

     if&#40; cmp == 0&#41; 
     &#123;
        holder = totalMemory;
                        
        for&#40; int k = 1; k < i; k++ &#41;
        &#123;
           if&#40; k != j || k < i &#41;
	        holder = holder - object&#91;k&#93;.size;
        &#125;
        if&#40; holder > size &#41;
        &#123;
           object&#91;j&#93;.name = Name;
 	     object&#91;j&#93;.size = size; 
           object&#91;j&#93;.location = object&#91;j-1&#93;.location + object&#91;j-1&#93;.size;
 
           if&#40; object&#91;j+1&#93;.location - object&#91;j&#93;.location - object&#91;j&#93;.size > 1 &#41;   
             swapObject&#40; j &#41;;
           cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <<endl;
	     cout << object&#91;j&#93;.name << " is being loaded at location "
                << object&#91;j&#93;.location << ". Memory looks like&#58; " << endl;

           j = 1000;
        &#125;
     &#125;
    &#125;
&#125;

void swapObject&#40; int j &#41;
&#123;
   char * name, * name2;
   int size, location, size2, location2;

   name = object&#91;j+1&#93;.name;
   size = object&#91;j+1&#93;.size;
   location = object&#91;j+1&#93;.location;

   object&#91;j+1&#93;.name = "Hole";
   object&#91;j+1&#93;.location = object&#91;j&#93;.location + object&#91;j&#93;.size;

   j++;  

   for&#40; int k = j; k == i+1; k++ &#41;
   &#123;
      name2 = object&#91;k+1&#93;.name;
      size2 = object&#91;k+1&#93;.size;
      location2 = object&#91;k+1&#93;.location;
      
      object&#91;k+1&#93;.name = name;
      object&#91;k+1&#93;.size = size;
      object&#91;k+1&#93;.location = location;
 
   &#125;

   i++;
&#125;
 
void Delete&#40; char * name &#41;
&#123;
   char *processName;
   int cmp;

   for &#40; int l = 2; l < 10; l++ &#41;
              &#123;
		   processName = object&#91;l&#93;.name;
               cmp = strcmp&#40;name,processName&#41;;

		   if&#40; cmp == ZERO &#41;
                   &#123;      
		      object&#91;l&#93;.name = "Hole";
			
 			if&#40; object&#91;l+1&#93;.name == "Hole" &#41;
                        &#123;
			   object&#91;l&#93;.size = object&#91;l&#93;.size + object&#91;l+1&#93;.size;
                        &#125; 
			else if&#40; object&#91;l-1&#93;.name == "Hole" &#41;
			&#123;
			   object&#91;l-1&#93;.size = object&#91;l-1&#93;.size + object&#91;l&#93;.size;
			&#125;

		      cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <<endl;
	            cout << object&#91;l&#93;.name << "is being removed from location "
                       << object&#91;l&#93;.location << ". Memory looks like&#58; " << endl;
		   &#125;
	      &#125;


&#125;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.