3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

Why don't you use c++ strings and vectors instead of re-inventing the wheel

#include <string>
#include <vector>
using std::string;
using std::vector;
// other using statements here

class str_pair
{
public:
     str_pair() { counter = 0; }

     str_pair(string ip, string uri)
     {
             this->uri = uri;
             this->ip = ip;
             counter = 0;
     }
     void setPair(string ip, string url)
     {
             this->uri = uri;
             this->ip = ip;
             counter = 0;

     }
public:
    string ip;
    string uri;
    int counter;
};

vector<str_pair> list_head;

int main(int argc, char* argv[])
{
    string_pair node;    
    node.setPair(argv[1],argv[2]);
    // add string_pair to the vector
    list_head.push_back(node);    
}

what are those pieces of code after line 35?

0

Its just the format we are suppose to follow, and the codes after line 35 are gonna be used to match the ip and the uri when they are passed on the command line.

these is what supposed to happen running the progam from command line and passing a parameter eg

./program_name and then the command U(uri) and then an ip address(192....)

now for the most important question where can I add the ip and the uri?

0

see the main() that I posted previously. If the format is ./test U <URL here> I <IP here> then url will be in argv[2] and ip will be in argv[4]. That assumes a space between U and the URL and another space between I and the IP address.

0

This is all good but we have to use pointers in the form i have shown in my code!!!!

0

1) "where can I add the ip and the uri?"

I'm not sure exactly you mean by that question.

It is possible, but ungainly, to have the user enter (add) all the data needed as input for the program from the command line. It is more common for the program to get the majority of the input it needs from the keyboard, a file, or some source other than the command line.

On the other hand I would assign (add) the data to each new node before it is added to the list, so probably between lines 31 and 32.

2) Having each str_pair object have it's own counter seems counter intuitive. Are you sure that's what you want?

3) All variables declared with the const keyword must have their value entered by the programmer before compilation, meaning the value of the const variable can not be information provided to the program at run time.

0

I want most of the data to be created at runtime that is why i am trying to use pointers. The purpose of the program is to find the corsponding uri for the given ip address!!

0

first the program needs to generate a linked list of those structures. To do that you will have to prompt for the structure values then add the structure to the list. Put that into a loop until the user says he/she wants to stop. You could also expedite this by reading the data from a data file so that you don't have to type them every time you run the program.

After that is finished prompt for and get input for the IP address to search for. Then iterate through the linked list comparing the IP address of each node to the IP address you just entered.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.