Problem description:
Determine whether the character ch is the same as a character in the string indicated by Str. If it is the same, nothing is done. If it is different, insert it to the end of the string.
Sample input:
ABCDE
F
Sample output:
Abcdef
The source code is as follows:
# Include <stdlib. h> # include <conio. h> # include <stdio. h> # include <string. h> void fun (char * STR, char ch) {While (* STR & * Str! = CH) // whether the string ch is a character that is not at the same time as a character specified by STR ++; // move the pointer to the next character if (* STR = '\ 0') // when the Pointer Points to the end of the string, execute the following code {STR [0] = CH; // Replace the '\ 0' value at the position pointed to by the pointer with the STR [1] =' \ 0' character in the CH variable '; // The next position of the pointer is re-assigned as the string ending sign '\ 0 '. } Void main () {char s [81], C; System ("CLS"); // clear screen function, header file # include <stdlib. h> printf ("\ n please enter a string:"); gets (s); // The keyboard accepts a string printf ("\ n please enter the character to search: "); C = getchar (); fun (S, C); // function call, transfer address, its value will change. Printf ("\ n the result is % s \ n", S );}
Program:
String insertion and string end flag