S
saraca means ashoka tree
The following code is the heart of a program that I wrote to extract
html tags from a webpage. How efficient is my code ?. Is there still
possible way to optimize the code. Am I using everything as per the
text book. I am just apprehensive whether this may break or may cause a
memmory leak. Any chance for it.
#define TOKN_SIZE 256
void tagfinder() {
char ch, *tokens;
int i, j ,len;
i=j=0;
//scan buffer holds the webpage as a string.
len = strlen(scan_buffer);
while(i < len) {
ch = scan_buffer[i++];
if(ch == '<') {
tokens = malloc(TOKN_SIZE*sizeof(char));
j=0;
while(ch != '>') {
ch = scan_buffer[i++];
if(j >= TOKN_SIZE)
tokens = realloc(tokens, (j+TOKN_SIZE) * sizeof(char));
if(ch != '>') {
tokens[j++] = ch;
tokens[j] = '\0';
}
}// end of while(ch != '>')
printf("%s\n",tokens);
free(tokens);
}//end of if(ch == '<')
}//end of while(len > 0)
}
html tags from a webpage. How efficient is my code ?. Is there still
possible way to optimize the code. Am I using everything as per the
text book. I am just apprehensive whether this may break or may cause a
memmory leak. Any chance for it.
#define TOKN_SIZE 256
void tagfinder() {
char ch, *tokens;
int i, j ,len;
i=j=0;
//scan buffer holds the webpage as a string.
len = strlen(scan_buffer);
while(i < len) {
ch = scan_buffer[i++];
if(ch == '<') {
tokens = malloc(TOKN_SIZE*sizeof(char));
j=0;
while(ch != '>') {
ch = scan_buffer[i++];
if(j >= TOKN_SIZE)
tokens = realloc(tokens, (j+TOKN_SIZE) * sizeof(char));
if(ch != '>') {
tokens[j++] = ch;
tokens[j] = '\0';
}
}// end of while(ch != '>')
printf("%s\n",tokens);
free(tokens);
}//end of if(ch == '<')
}//end of while(len > 0)
}