-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.c
121 lines (100 loc) · 1.95 KB
/
validate.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include"inverted.h"
/*Name:Bharath J
Date:
Description:
Input:
Output:*/
int insert_at_first(Slist **head, char * data)
{
/* Creating the new node */
Slist *new = malloc(sizeof(Slist));
/* Check whether new node created or not */
if (new == NULL)
{
return FAILURE;
}
/* Fill the parts of the node */
strcpy(new->f_name,data);
new->link = NULL;
/* If list is empty */
if (*head == NULL)
{
/*If *head is empty then create the first node */
*head = new;
return SUCCESS;
}
else
{
/* *head is not empty then store value i.e link in the temp variable */
Slist *temp = *head;
/* Stroring that new link in the head inserting the element at first */
*head = new;
/* Creating the link to next data */
new -> link = temp;
}
return SUCCESS;
}
int validate_n_store_filenames(Slist **head, char *filenames[],int argc)
{
int check;
if(argc < 2)
return FAILURE;
for(int i=1;i<argc;i++)
{
check=IsFileValid(filenames[i]);
if(check==NOT_PRESENT)
return FAILURE;
else if(check==FAILURE)
{
}
else
store_filenames_to_list(filenames[i],head);
}
return SUCCESS;
}
int IsFileValid (char* filename)
{
FILE* fptr = fopen(filename, "r");
if (fptr == NULL)
{
printf ("ERROR: The File %s is not present plz check the File ",filename);
return NOT_PRESENT;
}
else
{
fseek(fptr,0,SEEK_SET);
int set=ftell(fptr);
fseek(fptr,0,SEEK_END);
int end=ftell(fptr);
if(set==end)
{
return FAILURE;
}
else
return SUCCESS;
}
}
int store_filenames_to_list(char *f_name, Slist **head)
{
int flag=0;
Slist *temp;
if(head==NULL)
{
insert_at_first(head,f_name);
}
else
{
temp=*head;
while(temp!=NULL)
{
if(!strcmp(temp->f_name,f_name))
{
flag=1;
break;
}
temp=temp->link;
}
if(flag==0)
insert_at_first(head,f_name);
}
}