c语言有关于文件输入输出的问题

img


#include<stdio.h>
struct score
{
    float score1[10];
    float score2[10];
    float score3[10];
};
struct student
{
    char name[10];
    struct score scoremore;
};
int main()
{
    int i;
    struct student iboy;
    FILE* fp;
    if ((fp = fopen("c:\\f\\stduent.txt", "w")) == NULL)
    {
        printf("open file error!\n");
        exit(0);
    }
    printf("Please enter the student name and three score:\n");
    scanf("%s %.1f", iboy.name,iboy.scoremore.score1,iboy.scoremore.score2,
        iboy.scoremore.score3);
    printf("Please enter the student name and three score again(ctrl+z to quit):\n");
    while (!feof(stdin))
    {
        fprintf("%s %.2f %.2f %.2f", iboy.name, iboy.scoremore.score1,
            iboy.scoremore.score2, iboy.scoremore.score3);
        scanf("%s %.1f", iboy.name, iboy.scoremore.score1, iboy.scoremore.score2,
            iboy.scoremore.score3);
    }
    fclose(fp);
    return 0;
}

想问一下,我这段代码,运行的时候有点问题。好像不能达到题目的要求,该怎么解决


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

struct student
{
    char name[10];
    float score[3];
};
int main()
{
    struct student iboy;
    FILE* fp;
    if ((fp = fopen("c:\\f\\stduent.txt", "w")) == NULL)
    {
        printf("open file error!\n");
        exit(0);
    }
    printf("Please enter the student name and three score:\n");
    scanf("%s%f%f%f", iboy.name, &iboy.score[0], &iboy.score[1],
        &iboy.score[2]);
    printf("Please enter the student name and three score again(ctrl+z to quit):\n");
    while (!feof(stdin))
    {
        fprintf(fp,"%s %.2f %.2f %.2f\n", iboy.name, iboy.score[0], iboy.score[1],
            iboy.score[2]);
        scanf("%s%f%f%f", iboy.name, &iboy.score[0], &iboy.score[1],
            &iboy.score[2]);
    }
    fclose(fp);
    return 0;
}