Advertisement
Aseron

BeforeChaos

Oct 23rd, 2017
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     // 1c.______________________________________
  8.  
  9.     float pi = 3.1415926;
  10.     char* s = "kerulete";
  11.     double m = 6.23768e+24;
  12.  
  13.     printf("%.2f %12s %.3e", pi, s, m);
  14.  
  15.     printf("\n");
  16.  
  17.     // 2c.______________________________________
  18.  
  19.     int u1;
  20.     double v1,v2;
  21.  
  22.     FILE* input;
  23.  
  24.     // Eloszor kiirjuk, hogy tesztelhessuk.(zh-n nem kell)
  25.     // Igen, igy konnyebb, mint manual megnyitni es beleirni...xd
  26.    
  27.     /*
  28.     input = fopen("in.txt","w");
  29.  
  30.     if(input == NULL){
  31.         perror(input);
  32.         //abort();
  33.     }
  34.  
  35.     fprintf(input,"%d %f %f", 10, 10.123123, 12.123123);
  36.  
  37.     fflush(input);
  38.     */
  39.  
  40.     input = fopen("in.txt","r");
  41.  
  42.     if(input == NULL){
  43.         perror(input);
  44.         //abort();
  45.     /* itt abortolható lehetne a program,
  46.             ha csak ez a feladat szerepelne benne. */
  47.     }
  48.  
  49.     fscanf(input,"%d %lf %lf", &u1, &v1, &v2 );
  50.  
  51.     fclose(input);
  52.  
  53.     printf("%d %lf %lf\n", u1, v1, v2);
  54.  
  55.     // 3c.______________________________________
  56.  
  57.     int error = 666;
  58.  
  59.     fprintf(stderr,"A hibakod: %8X\n", error);
  60.  
  61.     // 4c.______________________________________
  62.  
  63.     double kiA[6] = {1.1,1.2,1.3,1.4,1.5,1.6};
  64.     double beA[6];
  65.  
  66.     FILE* inputB;
  67.  
  68.     // Eloszor kiirjuk, hogy tesztelhessuk.(zh-n nem kell)
  69.    
  70.     /*
  71.     inputB = fopen("a.bin","wb");
  72.  
  73.     if(inputB == NULL){
  74.         perror(inputB);
  75.         //abort();
  76.     }
  77.  
  78.     fwrite(kiA, 6*sizeof(double), 1, inputB);
  79.  
  80.     fflush(inputB);
  81.     */
  82.  
  83.     inputB = fopen("a.bin","rb");
  84.  
  85.     if(inputB == NULL){
  86.         perror(inputB);
  87.         //abort();
  88.     }
  89.  
  90.     fread(beA, 6*sizeof(double), 1, inputB);
  91.  
  92.     fclose(inputB);
  93.  
  94.     int i;
  95.  
  96.     for(i = 0; i < (int) (sizeof(beA) / sizeof(*beA)); i++){
  97.         printf("%.1lf ", beA[i]);
  98.     }
  99.     // i < 6 is boven eleg persze, csak igy "ujrafelhasznalhatobb"
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement