2013=字符串




#include <stdio.h> #include <stdlib.h> #define ERROR -1 #define OK 1 typedef struct { char *ch; int length; } heapstring; typedef struct { char item[100][80]; int last; }wordlisttype; typedef int status; status init(heapstring &t) { t.ch=(char *)malloc(sizeof(char)); return 1; } status strassign(heapstring &t,char *chars) { int i,j; char *c; init(t); if (t.ch) free(t.ch); for (i=0,c=chars; *c; ++i,++c) if (!i) { t.ch=NULL; t.length =0; } else if (!(t.ch=(char *)malloc(i*sizeof(char)))) return ERROR; else { for (j=0;j<i;j++) t.ch[j]=chars[j]; t.length =i; } return OK; } void outputstring(heapstring t) { int i; for (i=0;i<t.length ;i++) printf("%c",t.ch[i]); } status extractword(heapstring t,wordlisttype &wd) { int num=0,i=0,len=t.length ,label=-1,j=0; char p,q; p=' '; q=t.ch[i]; while (i<len) { if (p==' '&&q!=' ') num++; p=q; q=t.ch[i]; i++; } printf("\nnumber=%d\n",num); return 1; } main() { heapstring str; char *ch=" 1001 this is hhg a ff book!----- "; wordlisttype wd; strassign(str,ch); outputstring(str); extractword(str,wd); }

  

posted @ 2013-11-04 21:15  博园少主  阅读(150)  评论(0编辑  收藏  举报