| | |
Linked list search
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 30
Reputation:
Solved Threads: 0
What i am trying to to is the following
when user inputs ./test U www.google.com I <ip here>
same for ./test U <URL here> I <IP here>
using command line input argv and argc here is what i have done so far,
also a hint when where is showed add the ip addresses and uri.
when user inputs ./test U www.google.com I <ip here>
same for ./test U <URL here> I <IP here>
using command line input argv and argc here is what i have done so far,
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <string> using namespace std; struct str_pair { char ip [50]; char uri [50]; str_pair *next; int counter; }; str_pair *str_ptr;// pointer to an order struct, str_pair *list_head;// points to nothing initially. const int list_size=; [COLOR="Red"]i need to know the list size!![/COLOR] 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<list_size; 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->counter =i; } strcpy( str_ptr=list_head; while(str_ptr != NULL) {if(strcmp return(0); }
Last edited by Ancient Dragon; Apr 28th, 2008 at 9:22 am. Reason: add code tags, removed url and ip address
Why don't you use c++ strings and vectors instead of re-inventing the wheel
what are those pieces of code after line 35?
C++ Syntax (Toggle Plain Text)
#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?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2008
Posts: 30
Reputation:
Solved Threads: 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?
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?
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. Last edited by Ancient Dragon; Apr 28th, 2008 at 9:43 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jul 2005
Posts: 1,699
Reputation:
Solved Threads: 273
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.
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.
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.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Linked List Problem (C++)
- Double-linked list in contiguous memory. (C)
- Q: in Link List (Daubly Linked List) (C++)
- Searching linked list (C)
- Linked list search problems (Computer Science)
- help me on linked list (C)
- ordered linked list (C)
- To create contact manager using doubly linked list(c++) (C++)
Other Threads in the C++ Forum
- Previous Thread: a major windows programming problem..
- Next Thread: Program Compiles, and excecutes but crashes when run.
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data database delete desktop directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






