2013年5月8日水曜日

単語切り出しプログラムOCP.C(その2)


単語切り出しプログラム
通称ワンカップ:OCP.C

その1とその2をくっつけて
コンパイルしてください

LINUXの端末でコンパイルしてみてね
92行目のwhile文について

CPUがARMだとEEOFのまま
x86だとEOFに変更してね

$ gcc -o ocp ocp.c
$ ./ocp ocp.c

で切り出しプログラムソース自体を切り出しします
c言語のソースは省略可能で

$ ./ocp ocp

でもいけます





struct line *node_create()
{
   struct line *from;
   int size;

   size=sizeof(struct line);
   from=(struct line *)malloc(size);
   if(!from){
      printf("out of memory 1\n");
      exit(1);
   }
   from->next=NULL;
   from->count=0;
   from->gyo=0;
   from->pos=0;

   return from;
}

struct line2 *node2_create()
{
   struct line2 *from;
   int size;

   size=sizeof(struct line2);
   from=(struct line2 *)malloc(size);
   if(!from){
      printf("out of memory 2\n");
      exit(1);
   }
   from->next2=NULL;
   from->gyo=0;
   from->pos=0;

   return from;
}

struct line *shojun(struct line *temp){
   struct line *old,*now;

   now=stt;
   old=NULL;

   if(!last){
      temp->next=NULL;
      last      =temp;
      return temp;
   }
   while(now){
      if(strcmp(now->text,temp->text) == 0){
         old2=gcdata2=now->data2;
         while(gcdata2){
            if(gcdata2->next2) old2=gcdata2->next2;
            gcdata2=gcdata2->next2;
         }
         old2->next2=node2_create();
         old2=old2->next2;
         old2->gyo=temp->gyo;
         old2->pos=temp->pos;
         now->count++;
         return stt;
      }
      if(strcmp(now->text,temp->text) < 0){
         old=now;
         now=now->next;
      }
      else{
         if(old){
            old ->next=temp;
            temp->next=now;
            return stt;
         }
         else{
            temp->next=now;
            return temp;
         }
      }
   }
   last->next=temp;
   temp->next=NULL;
   last      =temp;
   return stt;
}

struct line *ryaku(struct line *temp){
   gcdata->count=1;
   gcdata->gyo=temp->gyo;
   gcdata->pos=temp->pos;
   gcdata->data2=node2_create();
   gcdata2=gcdata->data2;
   gcdata2->gyo=temp->gyo;
   gcdata2->pos=temp->pos;
   gcdata->next =node_create();
   olddata=gcdata;
   gcdata=gcdata->next;
}

void omake(int a, int b,int c, long *d){
   int i;
   for(i=a;i<b;i++){
       printf(   "[%c]=%ld  ",i+c,*(d+i));
      fprintf(fs,"[%c]=%ld  ",i+c,*(d+i));
   }
   printf("\n");
   fprintf(fs,"\n");
}



0 件のコメント:

コメントを投稿