#include<stdio.h>
//用到了exit(0),malloc等
#include<stdlib.h>
//备忘录里面用到了字符串函数
#include<string.h>
#include<math.h>
#include<conio.h>
//==========================================================================
//**************************************************************************
//备忘录中的结构体和函数
#define lenz sizeof(struct Word)
typedef struct Word{
char str[100];
struct Word *next;
}w;
//==================================================
//实现替换文件中的串
void convert(){
FILE *fp=fopen("indata.txt","r+");
if(fp==NULL){
printf("\tCan not open the file\n");
exit(0);
}
char temp[50],s[100],key[100];
printf("\t请输入替换结果:\n");
scanf("%s",key);
printf("\t请输入需要替换的目标:\n");
scanf("%s",s);
//建立链表
w *head=NULL,*p=NULL,*q=NULL;
int cnt=0;
//把文件中的串都读入链表 ,边读,边替换
while(!feof(fp)){
fscanf(fp,"%s",temp);
//r如果与替换目标相同,就直接copy正确的
if(strcmp(temp,s)==0){
strcpy(temp,key);
}
cnt++;
if(cnt==1){
p=malloc(lenz);
head=p;
}
strcpy(p->str,temp);
q=p;
p=malloc(lenz);
q->next=p;
}
q->next=NULL;
free(p);
p=NULL;
//文件指针回首,把串从链表读入文件
w *t=head;
fclose(fp);
fp=fopen("indata.txt","w");
rewind(fp);
while(t!=NULL){
if(t->next==NULL){
fprintf(fp,"%s",t->str);
}
else{
fprintf(fp,"%s ",t->str);
}
q=t->next;
free(t);
t=q;
}
fclose(fp);
printf("\n替换已完成\n");
}
//==================================================
//实现清除文件的内容
void gui0(){
FILE *fp=fopen("indata.txt","w");
fclose(fp);
printf("\n内容已清除\n");
}
//==================================================
//实现向文件中追加内容
void write(){
printf("\t请输入追加内容:\n");
FILE *fp=fopen("indata.txt","a");
if(fp==NULL){
printf("\tCan not open the file!\n");
}
char ch;
while((ch=getchar())!='!'){
fputc(ch,fp);
}
fclose(fp);
printf("\n追加完成\n");
}
//==================================================
//输出文件所有内容
void read(){
FILE *fp=fopen("indata.txt","r");
if(fp==NULL){
printf("\tCan not open the file!\n");
exit(0);
}
//全部读出
char s[100];
//,如果多输入的带空格或者换行符会多输出一行
while(!feof(fp)){
fscanf(fp,"%s",s);
printf("%s ",s);
}
fclose(fp);
printf("\n内容已全部读取\n");
}
//==========================================================================
//**************************************************************************
//日历相关的结构体和函数
typedef struct Year{
int year;
int month;
int day;
int week;
}Y;
//以这一天为判断周几的基准
Y std={2019,8,25,0};
//==================================================
//判断是否是闰年
int leap(int y){
if((y%4==0&&y%100!=0)||y%400==0){
return 1;
}
return 0;
}
//==================================================
//输出闰年与否
void out_leap(){
int year=0;
printf("\t请输入年:\n");
scanf("%d",&year);
if(leap(year)){
printf("%d是闰年\n",year);
}
else{
printf("%d不是闰年\n",year);
}
}
//==================================================
//判断某月有多少天
int bigmonth(int y,int m){
switch(m){
case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;
case 4:case 6:case 9:case 11:return 30;
case 2:if(leap(y)) return 29;return 28;
}
}
//==================================================
//为了输入英语版的星期
char * beautifyweek(int weekday){
char ss[50],*s=ss;
switch(weekday){
case 1:s="Mon";break;case 2:s="Tue";break;case 3:s="Wed"; break;case 4:s="Thu";
break;
case 5:s="Fri";break;case 6:s="Sat";break;case 0:s="Sun"; break;
}
return s;
}
//==================================================
//只计算两个日期相差多少天,以先后输出
int many(Y x,Y y){
int sum=0;
//计算整年
int i=0;
if(x.year!=y.year){
Y a={x.year,x.month,x.day},b={y.year,y.month,y.day};
if(a.year>b.year){
a=y;
b=x;
}
//计算年
int i=0;
for(i=a.year+1;i<b.year;i++){
sum+=365;
if(leap(i))
sum++;
}
//计算整月
for(i=a.month+1;i<13;i++){
sum+=bigmonth(a.year,i);
}
for(i=1;i<b.month;i++){
sum+=bigmonth(b.year,i);
}
//计算天
sum+=bigmonth(a.year,a.month)-a.day;
sum+=b.day;
}
//同年
else {
if(x.month!=y.month){
Y a={x.year,x.month,x.day},b={y.year,y.month,y.day};
if(a.month>b.month){
a=y;
b=x;
}
//计算整月
int i=0;
for(i=a.month+1;i<b.month;i++){
sum+=bigmonth(a.year,i)
大一C语言课程设计--多功能计算器
最新推荐文章于 2024-09-14 18:34:13 发布
这篇博客分享了作者在大一期间使用C语言进行课程设计,实现了多功能计算器的全过程。通过这个项目,作者深入理解了C语言的基本语法和编程技巧。
摘要由CSDN通过智能技术生成