第二题

将实数写入文件:从键盘输入若干实数(以特殊数值-1结束),分别写到一个文本文件中。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void){
    double number;
    
    FILE *fp;
    if ((fp = fopen("number.txt", "w")) == NULL) {
        printf("Open file error.\n");
        exit(0);
    }
    
    scanf("%lf", &number);
    
    while (number != -1 ) {
        fprintf(fp, "%lf ", number);
        scanf("%lf", &number);
    }
    
    if (fclose(fp)) {
        printf("Can not close the file!\n");
        exit(0);
    }
    
    return 0;
    
}

 

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2021-12-12
  • 2021-10-29
  • 2021-12-15
  • 2021-06-21
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案