Advertisement
Josif_tepe

Untitled

May 22nd, 2024
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int main(int argc, char * argv[]) {
  6.     if(argc < 3) { // brojot na argumenti e pomal od 3, sto znaci deka ne sme vnele dovolno za da imame ime na vlezna i izlezna datoteka
  7.         printf("Vnesete gi iminjata na datotekite preku komadna linija\n");
  8.         return 0;
  9.     }
  10.     FILE * in = fopen(argv[1], "r");
  11.     FILE * out = fopen(argv[2], "w");
  12.     if(in == NULL) {
  13.         printf("Ne vnesovte validen fajl za citanje\n");
  14.         return 0;
  15.     }
  16.     if(out == NULL) {
  17.         printf("Ne vnesovte validen fajl za pecatenje\n");
  18.         return 0;
  19.     }
  20.  
  21.     char niza[2000];
  22.     while(fgets(niza, 200, in) != NULL) {
  23.         int broj = 0;
  24.         int zbir = 0;
  25.         for(int i = 0; i < strlen(niza); i++) {
  26.             if(isdigit(niza[i])) {
  27.                 broj = broj * 10 + (niza[i] - '0');
  28.             }
  29.             else {
  30.                 zbir += broj;
  31.                 broj = 0;
  32.             }
  33.         }
  34.         fprintf(out, "%d\n", zbir);
  35.     }
  36.  
  37.    
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement