1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 char s1[10] = "abcd"; 6 char s2[10] = "ABCDEF"; 7 printf("s1 = %s\ns2 = %s\n",s1,s2); 8 strncpy(s1,s2,3); 9 printf("s1 = %s\ns2 = %s\n",s1,s2); 10 11 char string[17]; 12 char *ptr,c = ‘r‘; 13 strcpy(string,"This is a string"); 14 ptr = strchr(string,‘i‘); 15 if(ptr) 16 printf("the character %c is at position:%s\n",c,ptr); 17 else 18 printf("the character was not found\n"); 19 20 21 return 0; 22 } 23 24 s1 = abcd 25 s2 = ABCDEF 26 s1 = ABCd 27 s2 = ABCDEF 28 the character r is at position:is is a string 29 Press any key to continue
时间: 2024-10-09 00:40:29