-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathep4.c
68 lines (53 loc) · 1.16 KB
/
ep4.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tabela.h"
string readLine( FILE *infile ) {
string line;
int n, ch;
n = 0;
line = malloc( 100+1 );
while ( (ch = getc( infile) ) != '\n' && ch != EOF ) {
if ( n >= 100 ) {
free( line );
exit( EXIT_FAILURE );
}
line[n++] = ch;
}
if ( n == 0 && ch == EOF ) {
free( line );
return NULL;
}
line[n] = '\0';
return line;
}
int main( int argc, char *argv[] ){
//Tabela
Tab * tab = NULL;
//Arquivo
FILE *file;
file = fopen(argv[1], "r");
//Auxiliares
int k = 0, j = 0;
string aux;
aux = malloc(80);
string palavras;
if( file == NULL ) exit( EXIT_FAILURE );
while( ( palavras = readLine( file ) ) != NULL ){
k++;
int i;
for( i = 0; i <= strlen( palavras ) ; i++ ){
int n = palavras[i];
if( ( n >= 65 && n <= 90 ) || ( n >= 97 && n <= 122 ) ) aux[j++] = palavras[i];
else{
aux[j++] = '\0';
if( strlen(aux) > 0) inserir( &tab, aux, k );
j = 0;
}
}
}
imprimir( tab );
free( aux );
free( tab );
fclose( file );
}