String insertion and string end flag

Source: Internet
Author: User

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

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.