SHOW:
|
|
- or go back to the newest paste.
1 | // uloha-5-5.c -- Tyzden 5 - Uloha 5 | |
2 | // Michal Kovacik, 21.10.2013 08:06:41 | |
3 | ||
4 | #include <stdio.h> | |
5 | ||
6 | int main() | |
7 | { | |
8 | FILE *f1, *f2; | |
9 | int dlzkaf1=0, dlzkaf2=0, mindlzka, znaky=0; | |
10 | if ((f1=fopen("PRVY.TXT", "r"))==NULL || (f2=fopen("DRUHY.TXT", "r"))==NULL) | |
11 | { | |
12 | printf("Subor sa nepodarilo otvorit\n"); | |
13 | return 0; | |
14 | } | |
15 | while(getc(f1)!=EOF) | |
16 | dlzkaf1++; | |
17 | while(getc(f2)!=EOF) | |
18 | dlzkaf2++; | |
19 | if(dlzkaf1<=dlzkaf2) | |
20 | mindlzka=dlzkaf1; | |
21 | else | |
22 | mindlzka=dlzkaf2; | |
23 | rewind(f1); | |
24 | rewind(f2); | |
25 | for(; mindlzka>=1; mindlzka--) | |
26 | ((getc(f1))!=(getc(f2)))? znaky++:0; | |
27 | if((dlzkaf1-dlzkaf2==0) && znaky==0) | |
28 | - | printf("Subory su identicke\n"); |
28 | + | printf("Subory su identicke"); |
29 | else | |
30 | { | |
31 | - | printf("Pocet roznych znakov: %d\n", znaky); |
31 | + | (znaky==0)? 0:printf("Pocet roznych znakov: %d\n", znaky); |
32 | - | printf("Jeden zo suborov je dlhsi o %d znakov", (dlzkaf1<=dlzkaf2)? (dlzkaf2-dlzkaf1):(dlzkaf1-dlzkaf2)); |
32 | + | (abs(dlzkaf1-dlzkaf2)==0)? 0:printf("Jeden zo suborov je dlhsi o %d znakov\n", abs(dlzkaf1-dlzkaf2)); |
33 | } | |
34 | fclose(f1); | |
35 | fclose(f2); | |
36 | return 0; | |
37 | } |