String manipulation exercises and considerations for scanf ()

Source: Internet
Author: User

/* ============================================================================ name:string.c AUTHOR:LF Ve Rsion:Copyright:Your Copyright Notice Description: string manipulation exercises and considerations for scanf () 1 inserting strings 2 Remove characters from string 3 scanf () Considerations = = ========================================================================== * * #include <stdio.h> #include <stdlib.h> #include <string.h>void test1 (); void Test2 (); void test3 (); int main (void) {test1 (); Test2 (); Test3 (); return exit_success;} /** * String Insertion * Operation steps: * 1 Find the inserted position * 2 Save the insertion position after the string * 3 will be inserted after the position of the string truncated * 4 The original string with the string to be inserted into the group of the original string and the original string after the insertion position of the group to spell */void Test1 () {char insertstring[10]= "Hello VC"; char oldstring[40]= "Hello java hello C + + Hello C";p rintf ("oldstring=%s\n", oldstring) Char searchstring[10]= "C + +", char *p=strstr (oldstring,searchstring), if (p!=null) {char tempstring[20];strcpy ( Tempstring,p+strlen (searchstring));p rintf ("tempstring=%s\n", tempstring); * (P+strlen (searchstring)) = ' + ';p rintf ( "Oldstring=%s\n", oldstring); Strcat (oldstring,insertstring);p rintf ("oldstring=%s\n", oldstring), strcat (oldstring,tempstring);p rintf ("oldstring=%s\n", oldstring);} else {printf ("not found\n");} printf ("============\n");} /** * Delete characters in string */void test2 () {int location = 0;char oldstring[40] = "Hello java hello C + + Hello C";p rintf ("oldstring=%s\ n ", oldstring); char newstring[40];char Deletechar = ' l '; char *p = Oldstring;while (*p! = ') {if (*p! = Deletechar) {New String[location] = *p;location++;} else {}p++;} printf ("newstring=%s\n", newstring), strcpy (oldstring,newstring);p rintf ("oldstring=%s\n", oldstring);p rintf ("= = ========\n ");} /** * SCANF () Note * SCANF () will use spaces, tabs, spaces, line breaks, and page breaks as terminator to the data. * but gets () does not, so when the input string contains the above characters can get () */void test3 () {//char a[30];//scanf ("%s", a);//printf ("a=%s\n", a); Char b[30]; Gets (b);p rintf ("b=%s\n", b);

String manipulation exercises and considerations for scanf ()

Related Article

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.