高階語言程式設計課程第十次作業

hfdc發表於2024-12-03

這個作業屬於哪個課程:https://edu.cnblogs.com/campus/fzu/2024C

這個作業要求在哪裡: https://edu.cnblogs.com/campus/fzu/2024C/homework/13314

學號:092300125

姓名:張天榮

#include<stdio.h> 

int main(void){

    FILE* p=fopen("file1.txt","rt");
    FILE* h=fopen("file2.txt","wt");

    char c;
    while((c=fgetc(p))!=EOF)
        fputc(c,h);
    
    fclose(p);
    fclose(h);

    return 0;

}
#include<stdio.h> 

int main(void){

    FILE* p=fopen("file1.txt","rt");
    

    char c;
    int a=0;
    while((c=fgetc(p))!=EOF)
        a++;

    printf("%d",a);
    fclose(p);
    

    return 0;

}
#include<stdio.h> 

int main(void){

    FILE* p=fopen("file1.txt","rt");
    

    char c;
    
    while((c=fgetc(p))!=EOF)
        putchar(c);

    
    fclose(p);
    

    return 0;

}
#include<stdio.h> 

int main(void){

    FILE* p=fopen("file1.txt","rt");
    FILE* h=fopen("file2.txt","at");

    char c;
    
    while((c=fgetc(p))!=EOF)
        fputc(c,h);

    
    fclose(p);
    fclose(h);

    return 0;

}
#include<stdio.h> 

int Check(char* ch){
    
    while(*ch!='\0'){
        if(*ch=='a')
            return 0;
        ch++;
    }

    return 1;

}

int main(void){

    FILE* p=fopen("file1.txt","rt");
    FILE* h=fopen("file2.txt","wt");

    char ch[20];
    
    while(fgets(ch,20,p)!=NULL){
        if(Check(ch))
            fputs(ch,h);
    }
        

    fclose(p);
    fclose(h);

    return 0;

}
#include<stdio.h> 

int main(void){

    FILE* p=fopen("file1.txt","rt");

    fseek(p,0L,2);
        
    printf("%d",ftell(p));

    fclose(p);
    

    return 0;

}
#include<stdio.h> 
#include<string.h>

typedef struct Stu{
    char id[10];
    char name[30];
    int g1;
    int g2;
    int g3;
}Stu;

int main(void){

    FILE* p=fopen("file1.txt","wt");

    Stu arr[5];
    int i=0;
    char ch[30];

    for(i=0;i<5;i++){
        scanf("%s",ch);
        strcpy(arr[i].id,ch);
        scanf("%s",ch);
        strcpy(arr[i].name,ch);
        scanf("%d %d %d",&arr[i].g1,&arr[i].g2,&arr[i].g3);
    }

    int g[3]={0};
    for(i=0;i<5;i++){
        fprintf(p,"%s %s %d %d %d\n",arr[i].id,arr[i].name,arr[i].g1,arr[i].g2,arr[i].g3);
        g[0]+=arr[i].g1;
        g[1]+=arr[i].g2;
        g[2]+=arr[i].g3;
    }

    fprintf(p,"%d %d %d",g[0]/5,g[1]/5,g[2]/5);

    
    fclose(p);

    return 0;

}

相關文章