C语言复习——数组、字符串
2017-04-12 22:19
316 查看
编程练习:
2.删除一串字符串中指定的子串
/*编写一个杨辉三角的数组*/ #include <stdio.h> int main() { int n; int i = 0; int j = 0; int a[100][100]; printf("please input n:\n"); //输入输入的行数 scanf("%d",&n); for (i = 0;i < n ;i++) { for (j = 0;j < i+1;j++) { if(j==i||j==0) { a[i][j]=1; } else { a[i][j]=a[i-1][j-1]+a[i-1][j]; } } } for(i = 0;i < n;i++) { for(j=0;j<i+1;j++) { printf("%d ",a[i][j]); } printf("\n"); } return 0; }
2.删除一串字符串中指定的子串
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char a[20]; char *p=a; char *q; char *temp=(char*)malloc(sizeof(char)*20); int i; printf("please a:\n"); gets(a); printf("please temp:\n"); gets(temp); i=strlen(temp); while((q=strstr(p,temp))!=NULL) { strcpy(q,q+i); } puts(p); return 0; }
相关文章推荐
- C语言中字符数组和字符串指针分析
- 关于C语言字符串数组
- LoadRunner/C语言 实现字符串数组比较
- C语言中字符数组和字符串指针分析(转载)
- 数据结构与算法复习(10)—— 后缀数组与字符串问题
- C语言中字符数组和字符串指针分析
- c语言中的字符数组与字符串
- c语言 字符串数组的应用
- C语言中字符数组和字符串指针分析
- 字符数组和字符串 | C语言教程 | C语言系列教程
- 【C语言】数组--字符串初始化数组的方法分析
- C语言中字符数组和字符串指针分析
- C语言中字符数组和字符串指针分析
- 【C语言】学习笔记:字符串与字符数组
- 【转】c语言中的字符数组与字符串
- C语言速成手册(三):数组、字符串、结构
- c语言中的字符数组与字符串
- C语言中字符数组和字符串指针分析
- C语言中的指针之数组和字符串
- C语言中字符数组和字符串指针分析