建设部网站取消园林资质,形象型网站,跨国购物网站建设费用,国内php开发的网站建设题目一 第一步#xff1a;创建一个 struct Student 类型的数组 arr[3],初始化该数组中3个学生的属性 第二步#xff1a;编写一个叫做save的函数#xff0c;功能为 将数组arr中的3个学生的所有信息#xff0c;保存到文件中去#xff0c;使用fread实现fwrite 第三步#xf…题目一 第一步创建一个 struct Student 类型的数组 arr[3],初始化该数组中3个学生的属性 第二步编写一个叫做save的函数功能为 将数组arr中的3个学生的所有信息保存到文件中去使用fread实现fwrite 第三步编写一个叫做load的函数功能为 将文件中保存的3个学生信息读取后写入到另一个数组 brr 中去 第四步编写一个叫做 show的函数功能为 遍历输出 arr 或者 brr 数组中的所有学生的信息 第五步编写一个叫做 setMath 的函数功能为 修改 文件中 所有学生的数学成绩 代码 #include student.hNodePtr createHead()
{NodePtr H(NodePtr)malloc(sizeof(Node));if(NULLH){printf(申请空间失败\n);return NULL;}H-tailH;H-nextNULL;printf(头结点初始化完毕\n\n);return H;
}
NodePtr addData(NodePtr H)
{NodePtr newnode(NodePtr)malloc(sizeof(Node));if(NULLnewnode){printf(新节点申请失败\n);return NULL;}//原最后一个数据 指向处理H-tail-nextnewnode;//头结点指向处理if(NULLH-next){H-nextnewnode;//头指针处理}H-tailnewnode;//尾指针处理//本节点指针域处理newnode-nextNULL;//本节点数据域处理printf(姓名);fscanf(stdin,%s,newnode-data.name);printf(数学);fscanf(stdin,%lf,newnode-data.math);printf(语文);fscanf(stdin,%lf,newnode-data.chinese);printf(英语);fscanf(stdin,%lf,newnode-data.english);printf(物理);fscanf(stdin,%lf,newnode-data.physical);printf(化学);fscanf(stdin,%lf,newnode-data.chemical);printf(生物);fscanf(stdin,%lf,newnode-data.biological);return newnode;
}void save(NodePtr H,const char* Name_of_File)
{if(NULLH){printf(保存失败地址不合法\n);return;}//打开文件FILE* wfpfopen(Name_of_File,w);NodePtr tempH;//用于遍历while(temp-next!NULL){temptemp-next;fwrite(temp-data,sizeof(temp-data),1,wfp);}//关闭文件fclose(wfp);printf(数据已写入:%s\n\n,Name_of_File);
}void show(NodePtr H)
{NodePtr tempH;if(NULLH){printf(地址不合法\n);return;}while(temp-next!NULL){temptemp-next;printf(%s ,temp-data.name);printf(%lf ,temp-data.math);printf(%lf ,temp-data.chinese);printf(%lf ,temp-data.english);printf(%lf ,temp-data.physical);printf(%lf ,temp-data.chemical);printf(%lf\n,temp-data.biological);}printf(链表显示完毕\n\n);}void load(NodePtr H,const char* Name_of_File)
{//打开文件FILE* rfpfopen(Name_of_File,r);while(1){NodePtr newnode(NodePtr)malloc(sizeof(Node));int resfread(newnode-data,sizeof(newnode-data),1,rfp);if(EOFres|| 0res){free(newnode);newnodeNULL;break;}//指向处理//原最后一个数据 指向处理H-tail-nextnewnode;H-tailnewnode;//尾指针处理//本节点指针域处理newnode-nextNULL;//本节点数据域处理}//关闭文件fclose(rfp);printf(数据已载入链表\n\n);
} 结果 题目 使用 fread 和 fwrite 将一张任意bmp图片改成德旗 代码
int main(int argc, const char *argv[])
{FILE* wfpfopen(photo.bmp,r);int width0,height0;fseek(wfp,18,SEEK_SET);fread(width,4,1,wfp);fread(height,4,1,wfp);fseek(wfp,54,SEEK_SET);unsigned char red[3]{0,0,255};unsigned char yellow[3]{0,255,255};//黄色unsigned char black[3]{0,0,0};//黑色for(int i0;iwidth*height;i){if(iwidth*height*2/3){fwrite(black,3,1,wfp);}else if(iwidth*height/3){fwrite(red,3,1,wfp);}else{fwrite(yellow,3,1,wfp);}}fclose(wfp);return 0;
}结果