yyc5573 2021-03-12 21:50 采纳率: 100%
浏览 18
已采纳

大神们能帮我看看吗?我的emt函数里面的加粗语句出问题了,但不知道是为什么,恳请赐教

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N sizeof(struct check)
struct check
{
    char words[15];
    struct check * next;
}*L,*r,*p,*s;
FILE *f;
char ch;

int main()
{
    r=L=(struct check *)malloc(N);
    void read();
    void del();
    void emt();
    void del_word();
    void print();
    read();
    del();
    emt();
    del_word();
    print();
    return 0;
}

void read()
{        
    if(!(f=fopen("1.txt","r")))
    {
        printf("文件打开错误\n");
        exit(0);
    }
    while((ch=fgetc(f))!=EOF)
        putchar(ch);
    fclose(f);
    printf("\n\n\n\n\n\n\n\n\n删除链接后的内容\n\n\n\n\n");
}

void del()
{
    FILE *fp;
    fp=fopen("2.txt","w");
    int t=0;
    if(!(f=fopen("1.txt","r")))
    {
        printf("文件打开错误\n");
        exit(0);
    }
    while((ch=fgetc(f))!=EOF)
    {
        if(ch=='<')t=1;
        if(ch=='>')t=0;
        if(t);
        else if(ch!='>')fputc(ch,fp);
    }
    fclose(fp);
    fp=fopen("2.txt","r");
    while((ch=fgetc(fp))!=EOF)
        printf("%c",ch);
    fclose(f);
    fclose(fp);
}

void emt()
{
    int i=0,t=0,word=0; 
    if(!(f=fopen("2.txt","r")))
    {
        printf("文件打开错误\n");
        exit(0);
    }
    while((ch=fgetc(f))!=EOF)
    {
        if(ch==' ')
        {
            t=1;
            i=0;
        }
        if(t&&(ch>64&&ch<91||ch>96&&ch<123))
        {
            t=0;
            word++;
            p=(struct check *)malloc(N);
            r->next=p;
            r=p;
        }
        if(!t&&(ch>64&&ch<91||ch>96&&ch<123))
        {
            p->words[i]=ch;
            i++;
        }
    }
    r->next=NULL;
    printf("单词数目为%d个\n",word);
}

void del_word() //末尾情况探讨
{
    p=L->next;
    while(p)
    {
        s=p;
        r=p->next;
        while(r)
        {
            if(!strcmp(p->words,r->words))
            {
                s->next=r->next;
                delete r;
                r=s->next;
            }
            if(r)
            {
                s=s->next;
                r=r->next;
            }
        }
        p=p->next;
    }
}

void print()
{
    f=fopen("3.txt","w");
    p=L->next;
    while(p)
    {
        printf("%s\n",p->words);
        fprintf(f,"%s\n",p->words);
        p=p->next;
    }
    fclose(f);
}

  • 写回答

1条回答 默认 最新

  • 猫叔大鸭梨 2021-03-13 19:54
    关注

    指针p还没初始化吧

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看