/*
* 程序功能:以空格 tab 截断的单词,将大写转换为小写
* 作者版本日期:20151110 zhouhaib
* 源代码:ntpconf.c
* 代码存储位置 :
* 整体思路 :
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LINE_SIZE 1024
int split_string(char *str,char **array)
{
int cnt=(int) strlen(str);
char *p = str;
while((*p==' ')||(*p==' '))//遇到tab和空格处理
p++;
if(p>=str+cnt) return 0;//不输入
int ii=0;
char *b=(char *)malloc(100);
memset(b,0,100);
int j=0;
while(1)
{
if(p >=str+cnt) break;
if((*p =='
')||(*p =='
')) break; //换行
while((*p !=' ')&&(*p !=' ')&&(*p !='
')&&(*p !='
'))
{
b[j++] = tolower(*p);//把字符转换成小写字母,非字母字符不做出处理
p++;
}
array[ii++] =b;
b=(char *)malloc(100);
memset(b,0,100);
j=0;
if((*p =='
')||(*p =='
')) break;
while((*p==' ')||(*p ==' '))
{
p++;
if(p >=str+cnt) break;
}
}
return ii;
}
int main(int argc,char* argv[])
{
char buff[MAX_LINE_SIZE]={0};
char *array[10];
memset(array,0,sizeof(char*)*10);
int num,i;
printf("the word split by ' '
");
while(fgets(buff,MAX_LINE_SIZE,stdin))
{
printf("the word split by ' '
");
num =split_string(buff,array);
printf("num=%d
",num);
for(i=0;i<num;i++)
{
printf("array[i]=%s
",array[i]);
}
printf("input the word
");
}
}