Advertisement
masterm1nd99

редица

Jan 11th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 100
  3. void writeToFile() {
  4. FILE *f = fopen("matrica.txt", "w");
  5. char c;
  6. while((c = getchar()) != '#') {
  7. fputc(c, f);
  8. }
  9. fclose(f);
  10. }
  11. void printFile() {
  12. FILE *f=fopen("izlez.txt","r");
  13. char line[100];
  14. while(!feof(f)) {
  15. fgets(line,100,f);
  16. if (feof(f))
  17. break;
  18. printf("%s",line);
  19. }
  20. fclose(f);
  21. }
  22. int main() {
  23. writeToFile();
  24. FILE *f1, *f2;
  25. char c;
  26. int h, b, m[MAX][MAX], i, r, s = 0;
  27. if((f1 = fopen("matrica.txt", "r")) == NULL) {
  28. printf("Datotekata ne se otvora.");
  29. return -1;
  30. }
  31. fscanf(f1,"%d %d", &h, &b);
  32. for(i = 0; i < h&&!feof(f1); i++) {
  33. for(r = 0; r < b&&!feof(f1); r++) {
  34. fscanf(f1, "%d", &m[i][r]);
  35. }
  36. }
  37. fclose(f1);
  38. f2 = fopen("output.txt", "w");
  39. for(i = 0; i < h; i++) {
  40. for(r = 0; r < b; r++) {
  41. s=s+m[i][r];
  42. }
  43. if(s > 10) {
  44. printf("%d\n", s);
  45. }
  46. s = 0;
  47. }
  48. fclose(f2);
  49. printFile();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement