Advertisement
Josif_tepe

Untitled

Jan 20th, 2024
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. int main(int argc, const char * argv[]) {
  8.     if(argc < 3) {
  9.         printf("Vlezna i izlezna se vnesuvaat kako argumenti\n");
  10.         return 0;
  11.     }    
  12.     FILE *in = fopen(argv[1], "r");
  13.     FILE *out = fopen(argv[2], "w");
  14.  
  15.     if(in == NULL) {
  16.         printf("Ne validna vlezna datoteka\n");
  17.         return 0;
  18.     }
  19.     if(out == NULL) {
  20.         printf("Ne validna izlezna datoteka\n");
  21.     }
  22.     char s[2000];
  23.     int p = 0;
  24.     while(fgets(s, 1000, in) != NULL) {
  25.         int brojac = 0;
  26.         char zbor[2000];
  27.         int j = 0;
  28.         for(int i = 0; i < strlen(s); i++) {
  29.             if(isspace(s[i]) && s[i] != '\n') {
  30.                 for(int k =0 ; k < j; k++) {
  31.                     fprintf(out, "%c", zbor[k]);
  32.                 }
  33.                 if(brojac > 0) {
  34.                     fprintf(out, "-");
  35.                 }
  36.                 else {
  37.                     fprintf(out, " ");
  38.                 }
  39.                 brojac++;
  40.                 j = 0;
  41.             }
  42.             else if(s[i] == '\n') {
  43.                 for(int k = 0; k < j; k++) {
  44.                     fprintf(out, "%c", zbor[k]);
  45.                 }
  46.                 fprintf(out, ";\n");
  47.             }
  48.             else {
  49.                 zbor[j] = s[i];
  50.                 j++;
  51.             }
  52.         }
  53.         p++;
  54.     }
  55.     fprintf(out, "%d\n", p);
  56.     return 0;
  57. }
  58.  
  59.  
  60. /*
  61. 8
  62. 1 2 -1 -2 4 3 15  7  2
  63. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement