Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* broj reci je broj razmaka plus jedan
- while se ucitava broje se slova, kada naidje na razmak broj slova se upisuje u neki max slova
- do while pisi na neki fajl slova dok se ne dodje do razmaka*/
- int brojacReci(){
- FILE *f1 = fopen("test.txt", "r");
- char c;
- int brReci = 1;
- while (fscanf(f1, "%c", &c) !=EOF)
- {
- if (c == ' ')
- brReci++;
- }
- fclose(f1);
- return brReci;
- }
- void ispisNajReci(int n){
- int x = 0;
- char c;
- FILE *f2 = fopen("ispis.txt", "w");
- FILE *f1 = fopen("test.txt", "r");
- while (fscanf(f1, "%c", &c) !=EOF) {
- if (c==' '){
- x++; printf("%d\n", x);}
- if (x==2){
- fprintf(f2, "%c", c);}
- }
- fclose(f2);
- fclose(f1);
- }
- int main (){
- FILE *f1 = fopen("test.txt", "r");
- char c;
- int k = brojacReci();
- int brSlova = 0;
- int maxBr = 0;
- int najRec = 0;
- int num = 0;
- int naj = 0;
- while (fscanf(f1, "%c", &c) !=EOF) {
- brSlova++;
- if (c == ' '){
- num++;
- if ((brSlova-1)> maxBr){
- naj = num;
- maxBr = brSlova-1;}
- brSlova = 0;}
- }
- ispisNajReci(naj);
- printf("broj reci je: %d\t broj max slova je: %d\t najduza rec je : %d", k, maxBr, naj);
- fclose(f1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement