-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyclical_list.c
57 lines (55 loc) · 1.23 KB
/
cyclical_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "header.h"
extern Names *root;
Names *new(Names *actual)
{
Names *another;
another=malloc(sizeof(Names));
another->T=malloc(sizeof(char)*64);
actual->next=another;
another->prev=actual;
return another;
}
void build_list(char *arg)
{
Names *start;
bool guard=false;
struct dirent *de;
DIR *dr;
if(arg!=NULL) dr=opendir(arg);
else dr = opendir("photos");
if (dr==NULL)
{
printf("Could not open current directory\n");
}
else
{
de = readdir(dr);
while (de != NULL)
{
if(strstr(de->d_name,".jpg"))
{
if(guard==false)
{
guard=true;
root=malloc(sizeof(Names));
root->T=malloc(sizeof(char)*64);
strcpy(root->T,de->d_name);
start=root;
}
else
{
root=new(root);
strcpy(root->T,de->d_name);
}
}
de = readdir(dr);
}
if(guard==true)
{
root->next=start;
start->prev=root;
root=root->next;
}
}
free(dr);
}