SHARE
TWEET

Untitled

a guest Jun 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct time {
  6.    int second;
  7.    int minute;
  8.    int hour;
  9. }TIME;
  10. TIME *t= (TIME*)malloc(sizeof(TIME));
  11.  
  12. int main()
  13. {
  14.  
  15.    /*input.txt 생성*/
  16.    int i,size;
  17.  
  18.    FILE *fp = fopen("input.txt", "rt");
  19.    fscanf(fp, "%d", &size);
  20.    for (i = 0; i < size; i++) {
  21.       fscanf(fp, "%d %d %d", &t[i].hour, &t[i].minute, &t[i].hour);
  22.  
  23.    }
  24.  
  25.    srand(time(NULL));
  26.  
  27.  
  28.    fclose(fp);
  29.  
  30.    /*input.txt 에서 읽어 구조체에 저장*/
  31.    fp = fopen("output.bin", "wb");
  32.    fwrite(&size, sizeof(int), 1, fp);
  33.    for (i = 0; i < size; i++) {
  34.       fwrite(&t[i].hour, sizeof(int), 1, fp);
  35.       fwrite(&t[i].minute, sizeof(int), 1, fp);
  36.       fwrite(&t[i].second, sizeof(int), 1, fp);
  37.  
  38.    }
  39.  
  40.  
  41.       /*구조체에서 읽어 bin파일에 저장*/
  42.       fclose(fp);
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top