|
5鱼币
删字符串
- #include<stdio.h>
- #include<string.h>
- #define SIZE 100
- void dels(char*a1,char*a2);
- main()
- {
- char a1[SIZE] = "\0" ; //给待查找数组初始赋值
- char a2[SIZE] = "\0" ; //给对照数组初始赋值
- size_t len_des = 0 ; //对照数组的长度
- gets(a1); //给待查找数组赋值
- gets(a2); //给对照数组赋值
- dels(a1,a2);
- printf("\n"); //为了格式好看
- }
- void dels(char*a1,char*a2)
- {
- size_t len_a2 =strlen(a2); //对照数组的长度
- size_t i;
- for(i=0;a1[i]!='0';) //循环到a1这个待查找的数组结束循环
- {
- if(strncmp(&a1[i],a2,len_a2)==0) //在a1中查找a2的值
- {
- i+=len_a2; //就使a1跳过与a2相同的地方
- }
- else
- {
- putchar(a1[i]); //输出不同的地方
- i++;
- }
- }
-
- }
复制代码
结果为:
- iiss
- is
- is P @ 9 z@ L[ @ 4p+ Q&讦?
- --------------------------------
- Process exited after 4.958 seconds with return value 0
- 请按任意键继续. . .
复制代码
|
|