halo,

im a newer in this c++ program.i try to execute this code(at the attachment) at ns2 unbuntu 9.10 but the following error occur. help me fix this error.
analyze.cpp:55: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:55: error: ‘exit’ was not declared in this scope
analyze.cpp:61: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:61: error: ‘exit’ was not declared in this scope
analyze.cpp:67: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:67: error: ‘exit’ was not declared in this scope
analyze.cpp:73: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:73: error: ‘exit’ was not declared in this scope
analyze.cpp: In function ‘int main(int, char**)’:
analyze.cpp:196: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:196: error: ‘exit’ was not declared in this scope
analyze.cpp:205: error: ‘strcmp’ was not declared in this scope
analyze.cpp:221: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:221: error: ‘exit’ was not declared in this scope
analyze.cpp:226: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:226: error: ‘exit’ was not declared in this scope
analyze.cpp:232: error: ‘atoi’ was not declared in this scope
analyze.cpp:239: error: ‘EXIT_FAILURE’ was not declared in this scope
analyze.cpp:239: error: ‘exit’ was not declared in this scope
analyze.cpp:247: error: ‘system’ was not declared in this scope

Recommended Answers

All 9 Replies

You probably forgot to #include <cstdlib> .

i already try to put it but still got an error.
analyze.cpp: In function ‘int main(int, char**)’:
analyze.cpp:206: error: ‘strcmp’ was not declared in this scope

That's a different error. For strcmp, you need to #include <cstring> Here's a tip:
When you get a x-not-declared error, you go to google and type: x c++ , where x= the function name. So in this case strcmp c++ . Then you click the very first link, and it reads in the header

cplusplus.com C++ : Reference : C Library : cstring (string.h) : strcmp

And now you know that you need to include "cstring"

success fix it..thank you..:)..but why still cant execute the graph?

Don't know. Please post current code using [code] /* code here */ [/code] tags instead of using an attachment and I'll have a look.

sorry..i dont know how to use it..i try but still cant put code between it.

sorry..i dont know how to use it..i try but still cant put code between it.

- Click "reply"
- Click the [code] button
- select your code with the mouse.
- press ctrl-c
- go back to the replybox.
- put the cursor between the opening and closing tag
- press ctrl-v
- click submit reply

// Vaddina Prakash Rao
// Chair of Telecommunications
// TU Dresden


//The program needs the following files in the current directory for its successful operation.
//    1. performance.txt	file generated by autosim
//    2. drops.txt		file generated by autosim
//    3. find_avg868.awk	script file
//    4. dfind_avg868.awk	script file
//    
//The program generates these output files
//    1. new_performance868.txt file generated out of performance868.txt, excluding failed sims
//    2. new_drops868.txt	file generated out of drops868.txt, excluding failed sims
//
//And finally the graph values are generated in the following output files
//    1. final_graphs_868.txt	file generated out of new_performance868.txt
//    2. final_drops_868.txt	file generated out of new_drops868.txt


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdio.h>

using namespace std;

class Analyze
{
    private:
	ifstream in_file868, in_drops_868;
	ofstream out_file868, out_drops_868;
	vector<string> vec868, vec_drops868;
	int ideal_counts, max_counts;	
        
    public:
	Analyze(int icts=100, int mcts=135)
	    {
		ideal_counts = icts;
		max_counts = mcts;
		
		cout << "Ideal Counts = " << icts << endl;
		cout << "Max Counts = " << mcts << endl;
		    
		in_file868.open("performance.txt");
		in_drops_868.open("drops.txt");
		
		out_file868.open("new_performance868.txt", ios::trunc);
		out_drops_868.open("new_drops868.txt", ios::trunc);

		if (!in_file868)
		    {
			cout << "error opening file, performance868.txt\n";
			exit(EXIT_FAILURE);
		    }

		if (!in_drops_868)
		    {
			cout << "error opening file, drops868.txt\n";
			exit(EXIT_FAILURE);
		    }

		if (!out_file868)
		    {
			cout << "error opening file, new_performance868.txt\n";
			exit(EXIT_FAILURE);
		    }

		if (!out_drops_868)
		    {
			cout << "error opening file, new_drops868.txt\n";
			exit(EXIT_FAILURE);
		    }
	    }
	
	~Analyze()
	    {
		in_file868.close();
		in_drops_868.close();
		
		out_file868.close();
		out_drops_868.close();		
	    }
	    
	void read()
	    {
		string temp;
		while (getline(in_file868, temp))
		    vec868.push_back(temp);

		while (getline(in_drops_868, temp))
		    vec_drops868.push_back(temp);
	    }
	
	void arrange()
	    {
		string temp868, dtemp868;
		vector<string>::iterator ptr868, d_ptr868;
		string::size_type pos868, d_pos868;
		int left=-1, success=0;
		
		// All the four files should have the same number of lines. Its a requirement, else there is something
		// wrong in the way these files are created.
		for (ptr868=vec868.begin(), d_ptr868=vec_drops868.begin(); ptr868!=vec868.end(); ptr868++, d_ptr868++)
		    {
			//cout << success << "-" << left << endl;
			if ((success+left) < (max_counts-1))
			    {
				temp868 = *ptr868;
				dtemp868 = *d_ptr868;
			
				// Eliminate the headers
				if (temp868.find(":", 0)!=string::npos)
				    {
					vec868.erase(ptr868, ptr868+1);
					vec_drops868.erase(d_ptr868, d_ptr868+1);

					left++;
			    		ptr868--;
					d_ptr868--;
				    }
				else if (temp868.size() < 10)
				    {
					vec868.erase(ptr868, ptr868+1);
					vec_drops868.erase(d_ptr868, d_ptr868+1);

					left++;
					ptr868--;
					d_ptr868--;
				    }
				else
				    {
					// Extract the throughput
					pos868=temp868.find(" ");
					temp868.erase(pos868, (temp868.length()-pos868));
				
					// Check if the throughput is 0.
					if (temp868=="0")
					    {
						// If yes, discard the entry and move on to the next line
						vec868.erase(ptr868, ptr868+1);
						vec_drops868.erase(d_ptr868, d_ptr868+1);

						left++;
						ptr868--;
						d_ptr868--;
						continue;
			    		    }
				
					if (success == ideal_counts)
					    {
						left++;
						continue;
					    }
				    
					// Extract the simulation number
					// pos24=temp24.rfind(" ");
					// pos868=temp868.rfind(" ");
				
					// temp24.erase(0, pos24+1);
					// temp868.erase(0, pos868+1);
				
					// Now directly copy each line into a new file.
				
					success++;
					out_file868 << *ptr868 << endl;
					out_drops_868 << *d_ptr868 << endl;
				    }
			    }
			else
			    {
				if (success < ideal_counts)
				    {
					success++;
					out_file868 << *ptr868 << endl;
					out_drops_868 << *d_ptr868 << endl;
				    }
				left=-1;
				success=0;	
				out_file868 << endl;
				out_drops_868 << endl;
			    }
		    }
	    }
};


int main(int argc, char *argv[])
{
    int ictns, mctns;
    
    if (argc > 3)
	{
	    cout << "Excessive Parameters.\nUsage:\nPrototype: analyze <Ideal_Sims> <Max_Sims>\nEx: analyze 100 120\n";
	    exit(EXIT_FAILURE);
	}
    else if (argc == 1)
	{
	    ictns = 100;
	    mctns = 135;
	}
    else if (argc == 2)
	{
	    if ((strcmp(*(argv+1),"?")==0) || (strcmp(*(argv+1), "help")==0) || (strcmp(*(argv+1),"HELP")==0))
		{
		    cout << "\nUsage:\nanalyze <Ideal_Sims> <Max_Sims>\nEx: analyze 100 120\n";
		    cout << "The program needs the following files in the current directory for its successful operation." << endl;
		    cout << "    1. performance.txt	file generated by autosim" << endl;
		    cout << "    2. drops.txt		file generated by autosim" << endl;
		    cout << "    3. find_avg868.awk		script file" << endl;
		    cout << "    4. dfind_avg868.awk		script file" << endl;
		    cout << "The program generates these output files" << endl;
		    cout << "    1. new_performance868.txt 	file generated out of performance868.txt, excluding failed sims" << endl;
		    cout << "    2. new_drops868.txt		file generated out of drops868.txt, excluding failed sims" << endl;

		    cout << "And finally the graph values are generated in the following output files" << endl;
		    cout << "    1. final_graphs_868.txt	file generated out of new_performance868.txt" << endl;
		    cout << "    2. final_drops_868.txt	file generated out of new_drops868.txt" << endl;
		    cout << endl;
		    exit(EXIT_FAILURE);
		}
	    else
		{
		    cout << "Invalid Parameter. Type \"analyze [?/help/HELP]\"" << endl;
		    exit(EXIT_FAILURE);
		}
	}

    else if (argc == 3)
	{
	    ictns = atoi(*(argv+1));
	    mctns = atoi(*(argv+2));
	    
	    if (ictns > 200 || mctns > 300)
		{
		    cout << "Too many simulation iterations. The program is designed to reject large values.\n";
		    cout << "Please make sure that the values match the following conditions: ictns<=200 and mctns<=300\n";
		    exit(EXIT_FAILURE);
		}
	}
    
    Analyze objAnal(ictns, mctns); 
    objAnal.read();
    objAnal.arrange();
    
    system ("awk -f find_avg868.awk new_performance868.txt");    
    system ("awk -f dfind_avg868.awk new_drops868.txt");
       
    return 0;
}

Would you care to explain the problem?
Explain == good description with plenty of details
Explain != vague description with no useful information

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.