Huawei test-Child string separation and Huawei string Separation

Source: Internet
Author: User

Huawei test-Child string separation and Huawei string Separation

Description:
Input any string sequence through the keyboard. The string may contain multiple substrings separated by spaces. Compile a program to automatically separate the substrings and separate them with commas (,). At the end, add a comma (,) and store the substrings.
If "abc def gh I d" is input, the result will be abc, def, gh, I, d,
 
Required implementation functions:
Void DivideString (const char * pInputStr, long lInputLen, char * pOutputStr );
 
[Input] pInputStr: input string
LInputLen: length of the input string
[Output] pOutputStr: Output string. The space has been opened up and the length of the input string is equal to that of the input string;
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.


Example

Input: "abc def gh I d"

Output: "abc, def, gh, I, d ,"

#include<string.h>#include<stdio.h>void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr){    int j=0;    char pre='*';    for(long i=0;i<lInputLen;++i)    {        if(pInputStr[i]!=' ')        {            pOutputStr[j++]=pInputStr[i];        }        else if(pre!=' ')        {            pOutputStr[j++]=',';        }        pre=pInputStr[i];    }    pOutputStr[j++]=',';    pOutputStr[j++]='\0';}int main(int argc, char *argv[]){    char input[200];    char output[200];    while(gets(input))    {        DivideString(input ,strlen(input), output);        printf("%s\n",output);    }    return 0;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.