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 ");
    }
    }

  • 相关阅读:
    CF601B Solution
    CF847F Solution
    CF877D Solution
    CF1472F Solution
    CF1472G Solution
    CF1355E Solution
    CF912D Solution
    CF1167F Solution
    shell脚本自动备份MySQL数据库
    centos7 crontab笔记
  • 原文地址:https://www.cnblogs.com/zhouhbing/p/4953095.html
Copyright © 2011-2022 走看看