Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.  
  7. int vobroj=0;
  8. int brojac=0;
  9. int broj=0;
  10. int suma=0;
  11. FILE* dat1;
  12. FILE* dat2;
  13. dat2=fopen("rezultat.txt", "w");
  14.  
  15. char c;
  16. if((dat1=fopen(argv[1], "r"))==NULL){
  17. fputc(c, dat2);
  18. return -1;}
  19. while((c=fgetc(dat1))!=EOF){
  20. fprintf(dat2, "%c", c);
  21. if(isdigit(c)){
  22. if(vobroj==0){
  23. vobroj=1;
  24. broj=c-'0';
  25. brojac++;
  26. }
  27. else{
  28. broj*=10;
  29. broj+=c-'0';
  30. }
  31. }
  32. else{
  33. if(vobroj)
  34. //fprintf("%d", broj);
  35. vobroj=0;
  36. suma+=broj;
  37. broj=0;
  38. }
  39. }
  40. printf("Prosekot e %d", suma/(float)brojac);
  41. fclose(dat1);
  42. fclose(dat2);
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement