zoukankan      html  css  js  c++  java
  • 以空格截断数据

    /*
    * 程序功能:以空格 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 ");
    }
    }

  • 相关阅读:
    多线程创建方式四种

    归并排序
    Spark调优之--资源调优、并行度调优
    多线程中的上下文切换
    守护线程和本地线程
    线程和进程的区别
    3. 无重复字符的最长子串
    [蓝桥杯][历届试题]连号区间数
    [蓝桥杯][历届试题]蚂蚁感冒
  • 原文地址:https://www.cnblogs.com/zhouhbing/p/4953095.html
Copyright © 2011-2022 走看看