#include <stdlib.h> #include <stdio.h> #define N 10000 int main(char argc, char* argv[]) { int i, j, t; /* 字符串的最大长度为N, 然后查找p所指向的字符串在a串中出现过的次数 当输入终止符ctrl+z时,终止继续读入 */ char a[N], *p = argv[1]; for (i = 0; i < N-1; a[i] = t, i++) if ((t = getchar()) == EOF) break; a[i] = 0; for (i = 0; a[i] != 0; i++) { printf("%c",a[i]); } printf("字符串中字符个数-->%d ",i); for (i = 0; a[i] != 0; i++) { for (j = 0; p[j] != 0; j++) if (a[i+j] != p[j]) break; if (p[j]==0) printf("%d",i); } printf(" "); return 0; }