Ребят, помогите, пожалуйста, написать велосипед pwd на сях.
Вот, что набросал, получаю «ошибку сегментации (сделан дамп памяти)».
Уверен, что тут что с выделенмем памяти под эти указателями...
Указатели никогда не трогал почти, под unux пишу впервые.
Выручите, посмотрите, пожалуйста:
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
using namespace std;
int main()
{
    DIR* dir;
    struct  dirent* entry;
    struct stat st;
    char *cur_ent;
    char find_elem[100][20];
    char *last;
    char *end;
    strcpy(end,"home");
    strcpy(last, "OS3cpp"); // OS3cpp - название проги
    while(last!=end) {
        strcat(cur_ent,"//");
        printf("%s", last);
        strcat(cur_ent, last);
        chdir("..");
        dir = opendir(".");
        int i = 0;
        while ((entry = readdir(dir))!=NULL) {
            if(strcmp(entry->d_name, ".") == 0 && strcmp(entry->d_name, "..") == 0){
                stat(entry->d_name,&st);
                    if(S_ISDIR(st.st_mode)) {
                        strcpy(find_elem[i++], entry->d_name);
                    }
            }
        }
        int t = 0;
        while(t == 0) {
            i++;
            chdir(find_elem[i]);
            dir = opendir(".");
            while((entry = readdir(dir))!=NULL) {
                if(entry->d_name == last) {
                    chdir("..");
                    strcat(last,find_elem[i]);
                    t=1;
                } else chdir("..");
                t=1;
            }
        }
    }
    return 0;
}
Перемещено leave из general







