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;
    }
  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    14
    13
    12
    11
    10
    9
    8
    7
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14872995.html
Copyright © 2011-2022 走看看