Topic:
Finds the word in the given string (the word is made up of uppercase and lowercase alphabetic characters, and other non-alphabetic characters are treated as intervals of words, such as spaces, question marks, numbers, and so on; the other individual letters are not words) , and then output to a new string, and if a word recurs multiple times, output only once, and if the word is not found in the entire input string, output an empty string. The output words are separated by a "space", with no spaces after the last word.
Required implementation functions:
void My_word (charinput[], char output[])
"Enter" Char input[], enter the string
"Output" char output[], the output string
"Back" none
#include <stdio.h> #include <string.h> #include <stdlib.h>void my_word (char Input[],char output[]) { Char *p; Char *temp; Char *word[10]; int Len_input=strlen (input); int i,j; Char except[] = ","; Char *blank = ""; for (i=0;i<len_input;i++) {if (input[i]< ' A ' | | (input[i]> ' Z ' &&input[i]< ' a ') | | Input[i]> ' Z ') {input[i]= ', '; }} j=0; /* Save the removed word */p= strtok (input,except); while (null!=p) {word[j++]=p; p= strtok (null,except); } for (i=0;i<j;i++) printf ("%s", Word[i]);p rintf ("\ n"); int wordlen=j; /* Sort words in descending order of length, bubbling method */For (i=0;i<wordlen;i++) {for (j=1;j<wordlen-i;j++) {i F (strlen (Word[j-1]) <strlen (Word[j])) {temp=word[j]; WORD[J]=WORD[J-1]; Word[j-1]=temp; }}}/* Delete the same word */ for (i=0;i<wordlen;i++) {for (j=i+1;j<wordlen;j++) {if (strcmp (word[i],word[j ]) word[j]= "==0"; }//* Connect the word output */for (j=0;j<wordlen;j++) {if (j==0) strncpy (Output,word[j],strlen (word[j]) +1); else {strcat (Output,blank); strcat (Output,word[j]); }}} int main () {char input[] = "Some local buses, some1234123drivers"; printf ("String before Filtering:%s\n", input); Char output[30]; My_word (Input,output); printf ("Filtered string:%s", output); printf ("\ n"); return 0; }
Huawei Machine Test-Find word sort in string