Title Description:
Enter any string sequence through the keyboard, the string may contain multiple substrings, and the substrings are separated by a space. Write a program that automatically separates each substring and uses ', ' to separate it, and at the end adds a ', ' and stores the substring.
If you enter "ABC def GH i d", 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: Input string length
"Output" POUTPUTSTR: output string, space has been opened up, and input string length;
"Note" Only needs to complete the function algorithm, the middle does not need any IO input and output
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++]= ' + ';} 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;}
Huawei Machine Test-sub-string separation