|

楼主 |
发表于 2014-6-11 15:29:25
|
显示全部楼层
- #include<stdio.h>
- #include<string.h>
- #define NUM 100
- int lookup(char *src[],int n,char *tag[]);
- //src学生名数组首地址 n学生人数 tag保存刘姓学生
- int main()
- {
- char *src[NUM],*tag[NUM];
- int n,i,count=0; //n输入人数 i行下标 count计算刘个数
- printf("\n\n\n\n\n\t\t\t\t请输入学生个数 ");
- scanf("%d",&n);
- rewind(stdin); //清除回车
-
- for(i=0;i<n;i++)
- {
- gets(src[i]);
- }
-
- count=lookup(src,n,tag);
- printf("\n\t\t\t\t一共有刘氏学生%d个",count);
- for(i=0;i<count;i++)
- {
- puts(src[i]);
- }
-
- return 0;
- }
- int lookup(char *src[],int n,char *tag[])
- {
- char liu[] = "刘";
- int count = 0,i;
- for(i=0;i<n;i++)
- {
- if(!strcmp(src[i],liu))
- {
- strcpy(tag[count],src[i]);
- count ++;
- }
- }
- return count;
- }
复制代码 |
|