首页 > 其他 > 详细

记录英文单词

时间:2014-03-03 17:04:09      阅读:465      评论:0      收藏:0      [点我收藏+]

#include <iostream.h>
#include <string.h>
#include <malloc.h>
typedef struct link
{
    char* ch;
    int num;
    link* next;
}link;
int main(int argc, char* argv[])
{
    FILE *fp;
    fp=fopen("d:\\test.txt","r");
    char word[100000];
    int pos=0;
    char c;
    link *head, *pnow, *ptmp;
    head=NULL;
    pnow=NULL;
    ptmp=NULL;
    while (!feof(fp))
    {
        c=fgetc(fp);
        if ((c>=‘a‘&&c<=‘z‘)||(c>=‘A‘&&c<=‘Z‘)||(c==‘\‘‘))
            word[pos++]=c;
       else if (pos>0)
        {
            word[pos] = ‘\0‘;
           ptmp=head;
            while (ptmp)
            {
                if (strcmp(word, ptmp->ch)==0)
                {
                    ptmp->num++;
                   break;
                }
                ptmp=ptmp->next;
            }
            if (ptmp==NULL)
            {
                ptmp=(link*)malloc(sizeof(link));
                ptmp->ch=(char*)malloc(pos);
                strcpy(ptmp->ch, word);
                ptmp->num=1;
                ptmp->next=NULL;
                if (pnow)
                {
                    pnow->next=ptmp;
                    pnow=ptmp;
               }
              else
                    head=pnow=ptmp;
            }
            pos=0;
        }
    fclose(fp);
    ptmp=head;
    FILE *fp1=fopen("d:\\text.txt","w");
    while (ptmp)
    {
        fprintf(fp1,"%d\t%s\n", ptmp->num, ptmp->ch);
       ptmp=ptmp->next;
    }
    fclose(fp1);
    return 0;
}
}

记录英文单词,布布扣,bubuko.com

记录英文单词

原文:http://www.cnblogs.com/zuoyan123/p/3577453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!