WindFantasyZ 0 Newbie Poster

Hi, just need help with this code since it doesn't process the output ip or uri address when i input some numbers. I'm working on it right now as well to see if i can find what the problem is >.<

* The command line parameters will consist of a DNS command and
then a number of IP-URI string pairs.
The DNS command is always a single letter followed by a search string.
A string pairs is always IP address then URI which must be placed
in the DNS store.
The example below has the DNS command U, search string 74.1.2.3,
and two IP-URI pairs.
lab3_s1235567 U 74.1.2.3 74.125.19.1 www.google.com 74.1.2.3 www.abc.net

* The program must insert all string pairs into a classes which you create
and then executed the command and print the result (with an endl)
to standard out.
In the example above the command is asking to find the URI of the
IP address 74.1.2.3. The output should be www.abc.net.

* Commands include-
U ip_address : find the IP address ip_address in the link list and
print out the matching URI.
I uri_name : search the link list for the URI given and print out
the matching IP address.

* If the search does not find a match output the string "nil".

* Error checking is not an aim in this lab and so do not do any error
checking. For example assume that-
- all parameters can be treated as strings, don't check for
the correct formation of IP addresses or URIs.
- there will always be a string pair or URI and IP in the right order.
- the command will always be U or I with a search string following.
- there could be anywhere from zero to 20 string pairs
(hint: use argc to work it out).

* The C++ string class "string" must be used.
The C string routines such as strcmp must not be used.

* The solution may use only one while loop to get command line parameters
into classes. Do not use any loop construct such as for or do.
(This is make sure you use a class solution.)

* The bulk of the code must be held in a class you create named ip_uri_store.
Each class must hold one string pair (ip and uri string).
The class ip_uri_store must have a constructor which saves the
new ip and dns string.

* The program must create dynamic copies of the class and
use pointers in each class to links classes together.
The IP-URI information must be placed in this structure
and all searching must use this structure.
The tutors will check every program by eye to ensure this is
the solution method used.

*/

#define TEST
//#define TEST if (0)

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

//=== CLASS ip_uri_store ==================================================
class ip_uri_store
{
private:

	struct node
	{
		char ip[50] ;
		char uri[50] ;
		node *link;
	}*first;

public:
	ip_uri_store();
	void append(char* ip,char* uri);
	void search(char* command, char* searchvar);
};

ip_uri_store::ip_uri_store()
{
	first = NULL;
}



void ip_uri_store ::append(char* ip,char* uri)
{
 node *q,*t;

   if( first == NULL )
   {
		 first = new node;
		 strcpy(first->ip,ip);
		 strcpy(first->uri,uri);
		 first->link = NULL;
   }
   else
   {
        q = first;
      while( q->link != NULL )
           q = q->link;

      t = new node;
	  strcpy(t->ip,ip);
      strcpy(t->uri,uri);
      t->link = NULL;
      q->link = t;
   }

}

void  ip_uri_store::search(char *command, char *searchVar)
{
	for( node *p = first; p != NULL; p = p->link )
	{
		if(*command =='U')
		{
			if(strcmp(p->ip,searchVar) == 0)
			{
				cout<<"Found the query" <<endl  << p->uri
					<< endl;
				return ;
			}
		}
		else if (*command =='I')
		{
			if(strcmp(p->uri,searchVar)==0)
			{
				cout<<"Found the query" <<endl  << p->ip
					<< endl;
				return ;
			}
		}

	}

}

int main(int argc, char *argv[])
{//--- When no command line parameters MUST print id string in CSV format. 
	char *command = argv[1];
	char *searchVar = argv[2];

   if (argc == 1)  // no parameters.
    {
	 cout << "person's detail"
          << endl ;
       return(0) ;
	}  
  int i=3;
  ip_uri_store object1;

   while(i < argc)
	{

      object1.append(argv[i],argv[i+1]);
	  cout <<" added" <<argv[i] << argv[i+1] << endl;
	  i =i+2;
	}
   
   object1.search(argv[1],argv[2]);

     return(0) ;
   }
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.