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