#include <stdio.h>#include<string.h>intMainvoid){ //Char dest[10]; //#define NULL (void *) 0//char *dest = NULL; //dest is a wild pointer, the area pointed to is not readable space//Char dest[3]; //char src[] = "Hello"; Charstr1[Ten] ="Hello"; //char str2[10] = str1;strcpy (str2, str1); printf ("%s\n", STR2); //printf ("%s\n", strcpy (dest, SRC)); //printf ("%s\n", strncpy (dest, SRC, sizeof (dest))); return 0;}
#include <stdio.h>#include<string.h>hellohelloworldstrncmp ("Hello","HelloWorld",5);intMainvoid){ inti; Charname[][Ten] = {"xiaoming","Itcast","Xiaoqiang","Xiaohong"}; Charkey[Ten]; /*char a[10] = "Xiaoming"; Name[0] = = > A char b[10] = "Itcast"; Char c[10] = "Xiaoqiang"; Char d[10] = "Xiaohong"; */ //char name[][10] = {"Xiaoming\0\0itcast\0\0\0\0xiaoqiang\0xiaohong\0\0"}; for(i =0; I <4; i++) { if(strcmp (Name[i),"Xiaohong") ==0) {printf ("%d\t%s\n", I, name[i]); strcpy (Key, Name[i]); }} printf ("%s\n", key); return 0;}
#include <stdio.h>#include<string.h>intMainvoid){ //char s1[10] = "Hello"; //char *s1 = "Hello"; Chars1[7] ="Hello"; Note that S1 should have enough space to put the spliced string, or the array will be out of boundsCharS2[] =" Boy"; strcat (s1, S2); printf ("%s\n", S1); return 0;}
#include <stdio.h>#include<string.h>intMainintargcChar*argv[]) { CharStr[] ="Hello World Itcast"; Charkey; printf ("%s\n", str); Key=GetChar (); Char*p =NULL; P=STRCHR (str, key); (!p)? printf ("un find\n"):p rintf ("%s\n", p); return 0;}
#include <stdio.h>#include<string.h>/*int main (void) {char str[] = "Hello World itcast Good"; Char *p; p = strtok (str, ""); printf ("%s\n", p); while (p = strtok (null, "")) = null) printf ("%s\n", p);//P = strtok (str, ""); printf ("str =%s\n", str); return 0;}*//*int main (void) {char str[] = "Hello, world, itcast! Good.; Night? "; Char *dlim = ",?!.;"; Char dlim[] = ".?!.;"; Char *p; p = strtok (str, dlim); printf ("%s\n", p); while ((p = strtok (null, dlim)) = null) printf ("%s\n", p);//P = strtok (str, ""); printf ("str =%s\n", str); return 0;}*/size_t strlen (Const Char*str) { return 6;}intMainvoid){ CharStr[] ="Hello World itcast Good night"; CharTmp[] ="I am a student\n"; Char*dlim =" "; Char*p; printf ("%d\n", (int) strlen (TMP)); P= Strtok (str, dlim);//internal pointer saves the next string address to be strtokprintf"%s\n", p); P=strtok (TMP, Dlim); printf ("%s\n", p); while(P = strtok (NULL, dlim))! =NULL) printf ("%s\n", p); return 0;}
#include <stdio.h>intA =3;intb;intMainvoid){ intc =3; Char*STR1 ="Hello";//"Hello" is a string constant stored in a read-only data area CharStr2[] ="Hello";//Str2[6] Memory is allocated on the stack, and the properties of the stack are readable and writable.printf"%p\n", &a); printf ("%p\n", &b); printf ("%p\n", &c); printf ("%p\n", STR1); printf ("%p\n", &str1); printf ("%p\n", str2);//str2+1printf"%p\n", &STR2);//&str2+1 return 0;}
C-base-string manipulation function (Strlen,strcpy,strcmp,strcat,strstr,strtok)