-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.c
130 lines (113 loc) · 3.86 KB
/
delete.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
121
122
123
124
125
126
127
128
129
/* ************************************************************************ *
* Apagar errors.err quando vazio, VERSION 1.0 *
* BRIEF_DESCRIPTION *
* *
* Copyright (C) 2016 by Rafael Santos Pereira da Silva *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* To contact the author, please write to: *
* Rafael Santos Pereira da Silva <rafappr99@gmail.com> *
* Webpage: http://www.poli.com *
* Phone: +55 (81) 99345-0341 *
* ************************************************************************ *
*
*/
#include <stdio.h> /* Standard I/O functions */
#include <stdlib.h> /* Miscellaneous functions (rand, malloc, srand)*/
#include <getopt.h> /* get options from system argc/argv */
/* --------------------------------------------------------------------------*/
/**
* \brief
*
* \param argc
* \param argv[]
*
* \return
*/
int remover(void);
int imprimir(void);
int main(int argc, char *argv[])
{
FILE *dados= NULL;
char tem;
int opt, f=0, c=0;
/* getopt() configured options:
* -f forcado
* -c imprimir
*/
opterr = 0;
while((opt = getopt(argc, argv, "fc")) != EOF)
switch(opt)
{
case 'f':
f = 1;
break;
case 'c':
c = 1;
break;
case '?':
default:
printf("Type\n\t$man %s\nor\n\t$%s -h\nfor help.\n\n", argv[0], argv[0]);
return EXIT_FAILURE;
}
dados=fopen("errors.err","r");
if(dados!=NULL)
{
if(c)
{
imprimir();
if(f)
remover();
}
else
{
if(fscanf(dados, "%c", &tem) == EOF)
{
printf("Sem conteudo\n");
remover();
}
else
printf("Com conteudo\n");
if(f)
remover();
}
fclose(dados);
}
else
printf("Arquivo nao encontrado\n");
return EXIT_SUCCESS;
}
int remover(void)
{
int st;
st = remove("errors.err");
if(!st)
printf("Excluido com sucesso!\n");
else
printf("Falha na exclusao\n");
return st;
}
int imprimir(void)
{
char ch;
FILE *dados;
dados=fopen("errors.err","r");
while((ch=fgetc(dados))!= EOF)
printf("%c", ch);
fclose(dados);
return 0;
}