AnaGocevska

Untitled

Jan 29th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     int i, suma, broj,n;
  7.     char str[100], maxi_str[100];
  8.     FILE *fin;
  9.     FILE *fout;
  10.  
  11.     if((fin=fopen("vlez.txt", "r"))==NULL)
  12.     {
  13.         printf("Ne postoi.");
  14.         exit(1);
  15.     }
  16.  
  17.     if((fout=fopen("izlez.txt", "w"))==NULL)
  18.     {
  19.         printf("Ne postoi.");
  20.         exit(1);
  21.     }
  22.  
  23.     int maxi=0;
  24.     while(fgets(str,100,fin)!=NULL)
  25.     {
  26.         n=strlen(str);
  27.         i=0;
  28.         suma=0;
  29.         while(i<n)
  30.         {
  31.             if(isdigit(str[i]))
  32.             {
  33.                 broj=0;
  34.                 while(isdigit(str[i]))
  35.                 {
  36.                     broj=broj*10+(str[i]-'0');
  37.                     i++;
  38.                 }
  39.                 suma+=broj;
  40.             }
  41.             else
  42.             {
  43.                 i++;
  44.             }
  45.             if(suma>maxi)
  46.             {
  47.                 maxi=suma;
  48.                 strcpy(maxi_str, str);
  49.             }
  50.         }
  51.     }
  52.     fprintf(fout, "%s", maxi_str);
  53.     fclose(fin);
  54.     fclose(fout);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment