Meadowcreek_99 wrote:
> Write a function that takes as input a string containing HTML source
> code and returns both the # of images referenced in the code and the
> total screen area (in square pixels) occupied by the images
> The function MUST have the following declarationint
> estImageContent(char *pacHTML, long int *pliArea);
> 
> 
> 1. Prompt the user for an input filename
> 2. Open the file, read its contents into a string (up to 20000 bytes),
> close file
> 3. Call estImageContent()
> 4. Print the following to the screen:
> 1. Input filename
> 2. Estimated # of images
> 3. Estimated total screen area in square pixels
> 5. Loop back to prompt
<snip code>

Don't use gets().  Ever.

You haven't gotten very far since your first message.  You need to load 
the whole thing into memory as-is.  fgets() isn't really what I meant. 
Something more like fopen() the file for reading as binary, fseek() to 
the end, ftell(), fseek() to the beginning, read in the number of bytes 
specified by ftell() (malloc() beforehand - don't forget to free), 
fclose() the file and return the content.

(And you really should be using C++ for this - Safe C++ has BString, 
which has LoadFromFile(), which does the above.  One line of code is 
really all that is needed).

Then start scanning along until you find an open tag indicator and store 
the data up to that point as content.  Scan for the name, attributes, 
and values up to the close tag point.  Store all these as a tag.  Switch 
back to content mode.  Alternate until you have processed the entire file.

At that point you will have a set of structures that you can iterate 
through with a for-loop.  Looking for img tags and background attributes 
at this point is a piece of cake.

Then, output results, clean up everything (freeing struct's, etc.), and 
return to ask for another file.

(Ignore Sumit Chawla's question.  He probably didn't read/remember the 
original request.)

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.4
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to