IO进程线程day1作业

 

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
struct Student
{
    char name[16];
    int age;
    double math_score;
    double chinese_score;
    double english_score;
    double physics_score;
    double chemistry_score;
    double bio_score;
};
int main(int argc, const char *argv[])
{
    struct Student students[5] = {{"heishouge",30,88.5,90,91,55.5,66,70},
        {"daoge",29,80,85,8.5,0,91.5,77.5},
        {"huge",28,70,75.5,83.5,82,3,93},
        {"laoba",27,60,68.5,78.5,77.5,16,100},
        {"yujiangjun",23,13,14.5,27,46,47.5,0}};
    FILE* wfp = fopen("students_information.txt","w");
    if(wfp == NULL)
    {
        printf("打开文件失败\n");
        return 1;                                                                                                                                                                                    
    }

    for(int i=0;i<5;i++)
    {
        fprintf(wfp,"%s %d %.1f %.1f %.1f %.1f %.1f %.1f\n",
                students[i].name,
                students[i].age,
                students[i].math_score,
                students[i].chinese_score,
                students[i].english_score,
                students[i].physics_score,
                students[i].chemistry_score,
                students[i].bio_score);
    }
    fclose(wfp);

    FILE* rfp = fopen("students_information.txt","r");
    if(rfp == NULL)
    {
        printf("打开文件失败\n");
        return 1;
    }

    for(int i=0;i<5;i++)
    {
        printf("name:%s\n",students[i].name);
        printf("age:%d\n",students[i].age);
        printf("math_score:%.1f\n",students[i].math_score);
        printf("chinese_score:%.1f\n",students[i].chinese_score);
        printf("english_score:%.1f\n",students[i].english_score);
        printf("physics_score:%.1f\n",students[i].physics_score);
        printf("chemistry_score:%.1f\n",students[i].chemistry_score);
        printf("bio_score:%.1f\n",students[i].bio_score);
        printf("\n");
    }
    fclose(rfp);
    return 0;
}                                                                     

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值