Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157628
  • 博文数量: 76
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 15:15
文章分类

全部博文(76)

文章存档

2012年(2)

2011年(74)

我的朋友

分类: C/C++

2011-11-25 20:14:05

  1. #include <stdio.h>

  2. int main()

  3. {

  4. double eph[6];

  5. eph[0] = 937454.382812;

  6. eph[1] = 3126518.617188;

  7. eph[2] = 6271050.976562;

  8. eph[3] = 4030.750196;

  9. eph[4] = 5411.685772;

  10. eph[5] = -3296.477765;

  11.  

  12.  

  13. FILE *pfile;

  14. pfile = fopen("test.txt", "w");

  15.  

  16. printf("%d", sizeof(eph[0]));

  17. fwrite(eph, 8, 1, pfile);

  18. fwrite(eph + 1, 8, 1, pfile); // fwrite()的用法参见www.cplusplus.com

  19. fwrite(eph + 2, 8, 1, pfile);

  20. fwrite(eph + 3, 8, 1, pfile);

  21. fwrite(eph + 4, 8, 1, pfile);

  22. fwrite(eph + 5, 8, 1, pfile);

  23.  

  24. fclose(pfile);

  25.  

  26.  

  27. FILE *pfile2;

  28. pfile2 = fopen("test.txt", "r");

  29. double eph2[6];

  30.  

  31. fread(eph2, 8, 1, pfile2);

  32. fread(eph2 + 1, 8, 1, pfile2);

  33. fread(eph2 + 2, 8, 1, pfile2);

  34. fread(eph2 + 3, 8, 1, pfile2);

  35. fread(eph2 + 4, 8, 1, pfile2);

  36. fread(eph2 + 5, 8, 1, pfile2);

  37.  

  38. printf("%f\n", eph2[0]);

  39. printf("%f\n", eph2[1]);

  40. printf("%f\n", eph2[2]);

  41. printf("%f\n", eph2[3]);

  42. printf("%f\n", eph2[4]);

  43. printf("%f\n", eph2[5]);

  44. fclose(pfile2);

  45.  

  46. return 0;

  47. }

Output:

8937454.382812

3126518.617188

6271050.976562

4030.750196

5411.685772

-3296.477765

阅读(511) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~