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.
these are the two command i need to come up with:-
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".

for error checking :-
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 not be used.
The C string routines such as strcmp must used.

* The program must create dynamic copies of the struct below and
use pointers to links these structs 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.
I just need a start.

int main(int argc, char *argv[]){

   char *dns = argv[1];
   for(int i = 2; i < argc; i ++){
      char *IP_URI_pair = argv[i];
      // do something with the IP_URI_pair and the dns...
      }

   return 0;
   }

what should i do? create an array and attach it to it? please explain!!!

what should i do? create an array and attach it to it? please explain!!!

attach it to what exactly? I would say that you have more info/background on what your teacher wants you to do than I have.

I've probably given the wrong code before. This is because I don't know the commandline format. I assumed:

dns_search.exe U ip-uri ip-uri ip-uri ...

but on reading again it looks like it might be

dns_search.exe I uri ip uri ip uri ip uri ...
and
dns_search.exe U ip ip uri ip uri ...

in which case the code I should have posted before would be:

int main(int argc, char *argv[]){

   char *command = argv[1];
   char *searchVar = argv[2];

   for(int i = 3; i < argc; i += 2){
      char *ip = argv[i];         // this is one of the ip's from the commandline
      char *uri = argv[i+1];    // this is one of the uri's from the commandline
      // do something with the ip - uri pair and the command and searchVar here...
      }

   return 0;
   }

I just need a start.

And I believe this is what I have given.

okay i understand now, i have gave it a shot but i am kinda stuck
here is what i have done

struct str_pair
{

char ip [50];

char uri [50];

str_pair *next;

};

str_pair *str_ptr;// pointer to an order struct,

str_pair *list_head;// points to nothing initially.



int main(int argc, char *argv[])

{

if (argc == 1)

{
cout << "my name"<<endl;

return(0);
}

//--- initialize link list to empty.

list_head = NULL;// can test for NULL to see if anything is there.

//str_ptr = new str_pair;
//--- Create data at run time on the heap.

for (int i=0; i<argc ; i++)
{
str_ptr = list_head; // save old head of list.
list_head = new str_pair; // create new item.
list_head->next= str_ptr; // get next item to point to previous head.
list_head->next =i;

return(0);

}
}

what i need to know is how to introduce my uri and ip address and how do i attach them to the pointer? or maybe just hints

This article has been dead for over six months. Start a new discussion instead.