weixin_64513565 2022-11-28 12:03 采纳率: 66.7%
浏览 7
已结题

请问各位,我拿DEV-C++运行时,其中的“<1”显示有误,请问各位该如何解决?求解惑


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
typedef struct node 
{
    char name[20];
    //名称
    float price;
    //价格
    char productor[50];
    //生产商
    char pdate[15];
    //生产日期
    int day;
    //有效天数
    char fuction[200];
    //化妆品功能,暂未添加
    struct node *lchild;
    struct node *rchild;
}
toiletry;
toiletry *typein(toiletry *t);
///插入操作
void inorder(toiletry *t);
///中序遍历输出
toiletry *del(toiletry *t);
///删除某个化妆品的信息
void error();
///输入错误处理
struct tm *newtime;
char tmpbuf[128];
time_t lt1;
int main() 
{
    toiletry *head=NULL;
    int n;
    while(1) 
    {
        system("cls");
        ///刷新
        system("color 0e");
        time( <1 );
        newtime=localtime(<1);
        strftime( tmpbuf, 128, "         今天:  %Y  %m月%d日  %Ann", newtime);
        printf(tmpbuf);
        printf("n                 欢迎使用化妆品系统nn");
        printf("          ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆n");
        printf("          ☆  【1】   化妆品信息输入    ☆n");
        printf("          ☆  【2】   化妆品信息输出    ☆n");
        printf("          ☆  【3】   化妆品信息删除    ☆n");
        printf("          ☆  【0】        退出         ☆n");
        printf("          ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆n");
        scanf("%d", &n);
        if(n==1) head=typein(head);
        else if(n==2) inorder(head);
        else if(n==3) head=del(head);
        else if(n==0) break;
        else error();
    }
    system("cls");
    system("color 02");
    printf("n                  * *谢谢使用* *n");
}
toiletry *typein(toiletry *t)
{
    toiletry *f, *q, *p=(toiletry *)malloc(sizeof(toiletry));
    p->lchild=p->rchild=NULL;
    char na[20], pro[50], pdate[15];
    float price;
    int day, k=1;
    system("cls");
    system("color 0f");
    time( <1 );
    newtime=localtime(<1);
    strftime( tmpbuf, 128, "         今天:  %Y  %m月%d日  %Ann", newtime);
    printf(tmpbuf);
    printf("              ☆☆☆☆☆现在开始插入操作☆☆☆☆☆nn");
    printf("   请输入化妆品的信息:名称,价格,生产商,生产日期,有效天数:n");
    q=t;
    scanf("%s %f %s %s %d", p->name, &p->price, p->productor, p->pdate, &p->day);
    while(q)
    {
        if(p->price==q->price)
        {
            k=0;
            break;
        }
        f=q;
        q=(p->price<q->price)?q->lchild:q->rchild;
    }
    if(k)
    {
        if(t==NULL) t=p;
        else
        {
            if(p->price<f->price) f->lchild=p;
            else f->rchild=p;
        }
        printf("n         插入成功,按回车返回……");
    }
    else printf("n      化妆品价格已存在,按回车返回……");
    fflush (stdin);
    getchar ();
    return t;
}
void inorder(toiletry *t)
{
    system("cls");
    system("color 0d");
    toiletry *p=t;
    toiletry *stack[1000];
    int top=-1;
    time( <1 );
    newtime=localtime(<1);
    strftime( tmpbuf, 128, "         今天:  %Y  %m月%d日  %Ann", newtime);
    printf(tmpbuf);
    printf("  名称     价格      生产商      生产日期     有效天数nn");
    while((p!=NULL) || (top!=-1))
    {
        while(p)
        {
            top++;
            stack[top]=p;
            p=p->lchild;
        }
        if(top!=-1)
        {
            p=stack[top];
            top--;
            printf("  %-10s%-8.2f%-15s%-12s%-5dn", p->name, p->price, p->productor, p->pdate, p->day);
            p=p->rchild;
        }
    }
    if(t) printf("n            输出完毕,按回车返回……");
    else printf("n            文件为空,按回车返回……");
    fflush (stdin);
    getchar ();
}
toiletry *del(toiletry *t)
{
    toiletry *p, *q=NULL, *f;
    float price;
    char c;
    system("cls");
    system("color 0a");
    printf("              ☆☆☆☆☆现在开始删除操作☆☆☆☆☆nn");
    if(t==NULL)
    {
        printf("                      对不起,文件为空,不能删除nn");
        printf("                           请按回车返回……");
        fflush (stdin);
        getchar ();
        return t;
    }
    printf("             请输入您要删除的化妆品信息的价格 price = ");
    scanf("%f", &price);
    getchar();
    p=t;
    while(p)//查找要删除的结点
    {
        if(p->price==price) break;
        q=p;
        p=(price<p->price)?p->lchild:p->rchild;
    }
    if(p==NULL)//没有找到价格对应的化妆品的信息
    {
        printf("n                对不起,不存在该价格的化妆品nn");
        printf("                           请按回车返回……");
        fflush (stdin);
        getchar ();
        return t;
    }
    printf("n                  您要删除的化妆品的信息为:nn");
    printf("    名称     价格      生产商      生产日期     有效天数nn");
    printf("     %-10s%-8.2f%-15s%-12s%-5dn", p->name, p->price, p->productor, p->pdate, p->day);
    printf("nn                  您确定要删除吗?Y/Nn");
    scanf("%c", &c);
    if(c=='Y' || c=='y')
    {
        if(p->lchild==NULL && p->rchild==NULL)//待删结点的左右孩子都为空
        {
            if(q)//如果待删结点有双亲
            {
                if(p==q->lchild) q->lchild=NULL;
                else q->rchild=NULL;
            }
            else t=NULL;
            free(p);
        }
        else if(p->lchild!=NULL && p->rchild==NULL)//待删结点的左孩子不为空
        {
            if(q)//如果待删结点有双亲
            {
                if(p==q->lchild) q->lchild=p->lchild;
                else q->rchild=p->lchild;
            }
            else t=p->lchild;
            free(p);
        }
        else if(p->lchild==NULL && p->rchild!=NULL)//待删结点的右孩子不为空
        {
            if(q)//如果待删结点有双亲
            {
                if(p==q->lchild) q->lchild=p->rchild;
                else q->rchild=p->rchild;
            }
            else t=p->rchild;
            free(p);
        }
        else
        {
            f=p->rchild;
            while(f->lchild) f=f->lchild;
            f->lchild=p->lchild;
            if(q)
            {
                if(q->lchild==p) q->lchild=p->rchild;
                else q->rchild=p->rchild;
            }
            else t=p->rchild;
            free(p);
        }
        printf("n                已经删除成功,按回车返回……");
    }
    else if(c=='N' || c=='n') printf("n                已经取消删除,按回车返回……");
    fflush (stdin);
    getchar ();
    return t;
}
void error()
{
    system("cls");
    printf("nn      您的输入有误,按回车后请重新输入……");
    fflush (stdin);
    getchar ();
}
  • 写回答

1条回答 默认 最新

  • orbitgw C++领域新星创作者 2022-11-29 02:15
    关注

    你这语法就不对呀,不能这么写

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月7日
  • 已采纳回答 11月29日
  • 创建了问题 11月28日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么