Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 100
- void writeToFile() {
- FILE *f = fopen("matrica.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- void printFile() {
- FILE *f=fopen("izlez.txt","r");
- char line[100];
- while(!feof(f)) {
- fgets(line,100,f);
- if (feof(f))
- break;
- printf("%s",line);
- }
- fclose(f);
- }
- int main() {
- writeToFile();
- FILE *f1, *f2;
- char c;
- int h, b, m[MAX][MAX], i, r, s = 0;
- if((f1 = fopen("matrica.txt", "r")) == NULL) {
- printf("Datotekata ne se otvora.");
- return -1;
- }
- fscanf(f1,"%d %d", &h, &b);
- for(i = 0; i < h&&!feof(f1); i++) {
- for(r = 0; r < b&&!feof(f1); r++) {
- fscanf(f1, "%d", &m[i][r]);
- }
- }
- fclose(f1);
- f2 = fopen("output.txt", "w");
- for(i = 0; i < h; i++) {
- for(r = 0; r < b; r++) {
- s=s+m[i][r];
- }
- if(s > 10) {
- printf("%d\n", s);
- }
- s = 0;
- }
- fclose(f2);
- printFile();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement