Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include <limits.h>
  5.  
  6. #define true 1
  7. #define false 0
  8.  
  9. int main()
  10. {
  11.     FILE *f = fopen("m.dat", "r");
  12.     if (f == NULL) {
  13.         printf("No such file in this dirrectory (m.dat)");
  14.         exit(1);
  15.     }
  16.  
  17.     FILE *fw = fopen("g.dat", "w");
  18.     if (fw == NULL) {
  19.         printf("No such file in this dirrectory (g.dat)");
  20.         exit(1);
  21.     }
  22.  
  23.     int num = 0;
  24.     char c = fgetc(f);
  25.     char oldc = ' ';
  26.     int i = 0;
  27.  
  28.     while (true)
  29.     {
  30.         if (c == '-')
  31.         {
  32.             c = fgetc(f);
  33.             num = -1 * (c - '0');
  34.         }
  35.         else if (c == EOF || c == '\n') {
  36.             break;
  37.         }
  38.         else if (c == ' ')
  39.         {
  40.                 fprintf(fw, "%d ", num*num);
  41.                 num = 0;
  42.             }
  43.         else
  44.         {
  45.             num = num * 10 + (c - '0');
  46.         }
  47.         oldc = c;
  48.         c = fgetc(f);
  49.     }
  50.  
  51.     fclose(f);
  52.     fclose(fw);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement