Untitled
unknown
plain_text
3 years ago
2.1 kB
1
Indexable
Never
void traverseDirectories(const char* directory_name, char gender[1], char firstname[20], char lastname[20]){ DIR* dir = opendir(directory_name); int totalidx, startidx, endidx, z; if(dir == NULL){ return; } struct dirent* entity; entity = readdir(dir); while(entity != NULL){ if(entity->d_type == DT_DIR && strcmp(entity->d_name, ".") != 0 && strcmp(entity->d_name, "..") != 0){ char path[100] = {0}; strcat(path, directory_name); strcat(path, "/"); strcat(path, entity->d_name); traverseDirectories(path); //printf("%s\n", entity->d_name); } else if(entity->d_type == DT_REG){ FILE *entity_file; entity_file = fopen(entity->d_name, "r"); char buffer[256]; totalidx = 0; while(fgets(buffer, 256, entity_file)){ startidx = 0; endidx = 0; for (int i = 0; i < strlen(buffer); i++){ if(buffer[i] == ' '){ char currentword[20]; z = 0; for(int j = startidx; j < i; j++){ currentword[z] = buffer[j]; z++; } if(strcmp(currentword, firstname) == 0){ if(gender[0] == 'm' && buffer[startidx - 3] == 's'){ fseek(entity_file, startidx - 3, SEEK_SET); fputs('r', fptr); } if(gender[0] == 'f' && buffer[startidx - 3] == 'r'){ fseek(entity_file, startidx - 3, SEEK_SET); fputs('s', fptr); } if() } startidx = i + 1; } } totalidx += strlen(buffer); } } entity = readdir(dir); } closedir(dir); }