Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <dirent.h>
- #include <sys/types.h>
- void find_way(char* str, char** arr, const char* direct) {
- char next_dir[100];
- DIR* dir = opendir(direct);
- if(!dir)
- return;
- struct dirent* d = readdir(dir);
- while(d) {
- if(d->d_type == DT_DIR && strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
- strcpy(next_dir, direct);
- strcat(next_dir, "/");
- strcat(next_dir, d->d_name);
- find_way(str, arr, next_dir);
- }
- else if(d->d_type != DT_DIR) {
- int i;
- for(i = 0; i < strlen(str); i++) {
- if ((str[i] == d->d_name[0])&&(d->d_name[1] == '.')) {
- strcpy(arr[i], "./");
- strcat(arr[i], direct);
- strcat(arr[i], "/");
- strcat(arr[i], d->d_name);
- break;
- }
- }
- }
- d = readdir(dir);
- }
- closedir(dir);
- }
- int main() {
- char str[300];
- fgets(str, 300, stdin);
- int str_len = strlen(str);
- int arr_size = 100;
- char** arr = (char**)malloc(str_len*sizeof(char*));
- int i;
- for(i = 0; i < str_len; i++) {
- arr[i] = (char*)malloc(arr_size*sizeof(char));
- }
- FILE *result = fopen("result.txt", "w+");
- if(result)
- find_way(str, arr, "tmp");
- for(i = 0; i < str_len; i++)
- fprintf(result, "%s\n", arr[i]);
- fclose(result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement