Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.3 kB
1
Indexable
Never
urlStruct GetOutgoingUrls(char *url) {
        urlStruct outgoingUrls = urlStructNew();
        FILE *fp = fopen(url, "r");
        char line[100];
        int index = 0;
        bool started = false;
        while (fscanf(fp, "%s", line) == 1) {
            
                if (strcmp(line, "Section-1") == 0) {
                      started = true;
                      continue;
                }
                if (strcmp(line, "#end") == 0) {
                        outgoingUrls->size = index;
                        for (int i = outgoingUrls->size; i < NumberOfUrls(); i++) {
                            free(outgoingUrls->ListOfUrls[i]);
                        }
                        outgoingUrls->ListOfUrls = realloc(outgoingUrls->ListOfUrls, (outgoingUrls->size) * sizeof(char *));
                        break;
                } else if (started == true) {
                    if (index >= 1){ 
                        if (strcmp(outgoingUrls->ListOfUrls[index-1],line) == 0) {
                            continue;
                    } 
                    }   
                    strcpy(outgoingUrls->ListOfUrls[index], line);
                    index++; 
                }      
        }
        return outgoingUrls;
}