zoukankan      html  css  js  c++  java
  • 明解c语言 13-4

    1、

    #include <stdio.h>
    
    int main(void)
    {
        FILE *fp;
        char name[128];
        double height, weight;
        
        
        if((fp = fopen("a.txt", "w")) == NULL)
            printf("aFile open failed.
    ");
        else
        {
            int i;
            for(i = 0; i < 6; i++)
            {
                printf("NO%d.name = ", i + 1); scanf("%s", name);
                printf("NO%d.height = ", i + 1); scanf("%lf", &height);
                printf("NO%d.weight = ", i + 1); scanf("%lf", &weight);
                fprintf(fp, "%s %.2f %.2f
    ", name, height, weight);
            }
            fclose(fp);
        }
        return 0;
    }

    2、

    #include <stdio.h>
    
    int main(void)
    {
        FILE *fp;
        
        typedef struct{
            char name[128];
            double height;
            double weight;
        }Type1;
        
        int i;
        Type1 x[6];
        
        if((fp = fopen("a.txt", "w")) == NULL)
            printf("aFile open failed.
    ");
        else
        {
            for(i = 0; i < 6; i++)
            {
                printf("x[%d].name = ", i); scanf("%s", x[i].name);
                printf("x[%d].height = ", i); scanf("%lf", &x[i].height);
                printf("x[%d].weight = ", i); scanf("%lf", &x[i].weight);
                fprintf(fp, "%s %.2f %.2f
    ", x[i].name, x[i].height, x[i].weight);
            }
            fclose(fp);
        }
        return;
    }
  • 相关阅读:
    html与app交互
    算法:算法的时间与空间复杂度
    php加解密函数集合
    redis主要用法
    【原创】RabbitMQ教程:php实现
    安装RabbitMq
    mysql复制表和字段
    vim文本操作
    JAVA学习(常量)
    JAVA学习(变量)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14872995.html
Copyright © 2011-2022 走看看