设计的管理任务系统:直接上addtask的函数咯
然后检测是否有时间重复的任务,如果有的话便重新输入一遍
利用cin等函数实现输入任务 输入其他属性 如名字、优先级等等同时设置缺省值
将任务属性存入文档
void AddTask()
{
char flag=1;//用flag来判定时间其是否重复
char taskname[1000];
char tasktime[13],tasktype[10]={0},taskpriority[10]={0};
char str[512];
FILE *out;
out=fopen("/home/code/Desktop/Homework/task.txt","a+");
cout<<"[ system prompt ] Please enter the time when the task begins(such as 202207080101) "<>tasktime;
//判断是否存在相应tasktime
fseek(out, 0, SEEK_SET); //将文件指针移到文件头
while( fgets(str, 500, out) != NULL )
{
str[12] = ' ';
if( strcmp(str,tasktime) == 0 )
{
flag=0; }}
if(!flag) {cout<<"< system warning ! > A task with the same start time already exists"<>tasktime;}
tasktime[12] = ' ';
//cout<<"[ system prompt ] Please enter the exact time when the task begins (such as 0708)"<>N;
//cout<<"[ system prompt ] Please enter a reminder time for this task(such as 202304050203)"<>D;
cout<<"[ system prompt ] Please enter the task name"<>taskname;
cout<<"[ system prompt ] Please enter the task type(you can enter study, play and so on)"<* "<>tasktype;
if(tasktype[0]=='*')
{tasktype[0]='s';tasktype[1]='t';
tasktype[2]='u';tasktype[3]='d';
tasktype[4]='y'; }
cout<<"[ system prompt ] Please enter the task priority(you can enter high ,medium and low)"<*"<>taskpriority;
if(taskpriority[0]=='*')
{taskpriority[0]='l';taskpriority[1]='o';
taskpriority[2]='w';}
if(out!=NULL)
{
fputs(tasktime,out);
fputs("n",out);
fputs("taskid: ",out);
fputs(tasktime,out);
fputs(" name: ",out);
fputs(taskname,out);
fputs(" type: ",out);
fputs(tasktype,out);
fputs(" priority: ",out);
fputs(taskpriority,out);
fputs("n",out);
fclose(out);
}



