(ficheros ) me peta y no doy con el error
Publicado por mau (1 intervención) el 13/06/2017 15:54:41
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
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <time.h>
int main(int argc, char *argv[])
{
char matricula[20],cadena[80],euros[10];
FILE *p,*sortida;
int importmulta, pendent=0, cobrat=0, k, conta=0, x;
matricula[0]='*';
matricula[1]='\0';
strcat(matricula,argv[1]);
strcat(matricula,"*");
p=fopen("trafic.dat","r");
sortida=fopen("sortida.dat","w");
while(!feof(p))
{
fgets(cadena,80,p);
if(strstr(cadena,matricula)!=NULL)
{
fputs(cadena,sortida);
for(k=0,conta=0;cadena[k]!='\0'; k++)
{
if (cadena[k]=='*')
conta++;
if (conta==2)
{
k++;
for(x=0; cadena[k]!='/';k++,x++)
{
euros[x]=cadena[k];
}
euros[x]='\0';
break;
}
}
importmulta=atoi(euros);
if (strncmp(cadena,"SI",2) ==0)
{
cobrat+=importmulta;
}
else
{
pendent+=importmulta;
}
}
}
fprintf(sortida,"\nImport pendent de cobrament.: %d", pendent);
fprintf(sortida,"\nImport cobrat..........................: %d", cobrat);
fclose(p);
fclose(sortida);
return 0;
}
Valora esta pregunta
0