Advertisement
BORUTO-121

longestArray+1

Sep 19th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void unesi(char niz[], int velicina) {
  4.     char znak = getchar();
  5.     if (znak == '\n') znak = getchar();
  6.     int i = 0;
  7.     while (i < velicina-1 && znak != '\n') {
  8.         niz[i] = znak;
  9.         i++;
  10.         znak = getchar();
  11.     }
  12.     niz[i] = '\0';
  13. }
  14.  
  15. int main(){
  16.     char input[100],output[100];
  17.     printf("Unesite ulaznu datoteku: ");
  18.     unesi(input, sizeof input);
  19.     FILE* open=fopen(input, "r");
  20.     if(open==NULL){
  21.         printf("Daoteka %s ne postoji",input);
  22.         return 1;
  23.     }
  24.     printf("Unesite izlaznu datoteku: ");
  25.     unesi(output, sizeof output);
  26.     FILE* izlaz=fopen(output,"w");
  27.  
  28.     int c,pozMax,max=0;
  29.  
  30.     while((c=fgetc(open))!=EOF){
  31.         int poz=ftell(open)-1;
  32.         int slovo=c,brojac=1;
  33.         for(c=fgetc(open);c!=EOF && c==slovo+1;c=fgetc(open),brojac++) slovo=c;
  34.  
  35.         if(brojac>max) max=brojac,pozMax=poz;
  36.  
  37.         if(c==EOF)break;
  38.         fseek(open, -1, SEEK_CUR);
  39.     }
  40.     int i;
  41.     fseek(open,pozMax,SEEK_SET);
  42.     for(i=0,c=fgetc(open);i<max && c!=EOF;i++,c=fgetc(open))
  43.         fputc(c,izlaz);
  44.     fclose(open);
  45.     fclose(izlaz);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement