From the assignment:
If the program is run with zero or more than one command-line argument, it should print an informative error message and exit; it should to the same if any errors occur while getting the document.
From get.h
:
The storage chunk referenced by document should be freed by the caller.
main() // check for a command line argument. pull the url if there was an error print an error message else print the url resource
c | n | - | + | y | |||
cmdl | 0 | 2 | 0 | 0 | 19 | ||
get | 0 | 2 | 0 | 10 | 9 | ||
jpeg | 0 | 13 | 0 | 4 | 4 | ||
bad | 0 | 4 | 0 | 0 | 17 | ||
cmnt | 0 | 8 | 0 | 0 | 13 | ||
del | 0 | 16 | 0 | 0 | 5 | ||
size | 0 | 0 | 0 | 0 | 21 |
If you allocate it, you free it.
get()
allocates dynamic storage; make sure you free it.
main()
is not freeing dynamic storage.
main()
.
free
vs. delete
new
and delete
are the dynamic storage routines in C++.
new
procedures in C++.
malloc()
(and friends) and free()
are part of C.
new
and delete
over malloc()
(and friends) and
free()
in C++ programs.
free()
with new
.
free()
is not C++ aware.
my_document.data = new char [size];free(my_document.data);delete [] my_document.data;
// get() returns the error string. If there // were errors, the error string is printed // and data is empty; otherwise, the error // string is empty and data is printed. std::cout << get(argv[1], page) << "\n"; std::cout << page.data << "\n";
get()
document should have been clarified.
string tf; if ((tf = get(argv[1], doc)) == "") cout << "URL Retreived" << doc.data << endl;
*** *** simple get test *** 1c1 < URL RetreivedHTTP/1.0 200 OK --- > HTTP/1.0 200 OK 825d824 <
new
and delete
and malloc()
and free()
and never the
twain shall meet.
This page last modified on 16 September 2003.