/* ============================================================================ 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 ()