Need help with readchunk program.

Currently I'm trying to write a program that requests a file from a web server and parses the file to count the instances of a string. In this case, I'm looking for instances of a particular font (<b>, <i>, etc.)

While processing the file, the program is meant to do this in chunks, based on the byte size input from the user and will be no greater than 1000.

Right now, I'm working on a function, readchunk, that reads from the sock until it gets the specified number of bytes by calling recv(2) as many times as it needs to.

Note: This does not count partial tags between chunks.

This is all I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
ssize_t readchunk(int sockfd, void *buf, size_t len) 
{

/* Define readchunck to return exactly len bytes unless an error occurs or the socket closes. 
*/
    len = 1000;
    char* chunk = new char[len];
    read(sockfd, buf, 1000); //read file
    for( int i = 0; i < len; i++ ) { //loop to check through 1000 bytes
        //list chunks and <b> count
    }
    for( int i = 0; i < len; i++ ) { //repeating this process for all known tags.
        //list chunks and <strong> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <i> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <em> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <mark> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <small> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <del> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <ins> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <sub> count
    }
    for( int i = 0; i < len; i++ ) {
        //list chunks and <sup> count
    }
    close(sockfd);
}


I'm assuming I would need to create another loop that would go through this until it reaches EOF, but I'm not sure how to do that...I'm also not sure how to get each for loop to find the necessary strings...
Bump
Bump2
Bump3
Topic archived. No new replies allowed.