Advertisement
kiril_cvetkov

Untitled

May 29th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. //
  2. // main.c
  3. // datoteki
  4. //
  5. // Created by Kiril Cvetkov on 28.5.16.
  6. // Copyright © 2016 Kiril Cvetkov. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12.  
  13. #define MAX 100
  14.  
  15.  
  16.  
  17. //TIP 2
  18. void analizirajRecenica(FILE * datoteka)
  19. {
  20. char recenica[MAX+1]; // maksimalna dolzina na red(recenica)
  21.  
  22. float maksimalenOdnos=-1;
  23. int maksimalenIndeksNaRedica=-1;
  24. int counter =0;
  25. while(fgets(recenica, "%s", datoteka))
  26. {
  27. float counterLower=0;
  28. float counterUpper = 0;
  29. for(int i=0; i<strlen(recenica); i++)
  30. {
  31. if(isalpha(recenica[i]))
  32. {
  33. if(islower(recenica[i]))
  34. {
  35. counterLower++;
  36. }
  37. else
  38. {
  39. counterUpper++;
  40. }
  41. }
  42. }
  43. float odnos = counterUpper/ counterLower;
  44. if(odnos>maksimalenOdnos)
  45. {
  46. maksimalenOdnos = odnos;
  47. maksimalenIndeksNaRedica = counter;
  48. }
  49. printf("%f\n%s \n", counterUpper/counterLower, recenica);
  50. counter++;
  51. }
  52. printf("%d", maksimalenIndeksNaRedica);
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
  59. int main(int argc, const char * argv[]) {
  60. // insert code here...
  61.  
  62. FILE *datotekaInput;
  63.  
  64.  
  65. if((datotekaInput=fopen("text.txt","r"))==NULL)
  66. {
  67. puts("Ne validno");
  68. }
  69.  
  70. analizirajRecenica(datotekaInput);
  71. fclose(datotekaInput);
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement