2013=字符串
2013-11-04 21:15
357 查看
#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); }
相关文章推荐
- jquery选择器之属性过滤选择器
- hadoop commands(hadoop-2.0.0-cdh4.4.0)
- CSharp调用Matlab编译的dll
- 应用程序基础之03Manifest文件 (二)
- c语言 字符数组 与 字符串
- Spring 整合quartz
- Xp系统优化 虚拟内存(5)
- 跨线程访问UI控件,请赏鉴
- java基础学习day08总结
- 【转】POJ 1009
- JSP乱码问题
- Sprite Kit -- Sprite (3)
- Qt中 int ,float ,double转换为QString
- 用Thymeleaf替换JSP
- 知识管理系统
- AIX HA切换脚本问题总结
- linux IPI
- linux c 开发工具gcc gdb的使用:
- 监听是否与数据库建立了连接
- ClassLoader and 插件化设计