曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4475|回复: 0
打印 上一主题 下一主题

找出一个串中的单词"PASCAL"的个数

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34397
跳转到指定楼层
楼主
发表于 2008-11-22 09:58:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <stdio.h>

#include <string.h>



int main(void)

{

     char str[500];



    const  char *ptr = "pascal";



    char *ptr_t = (void *)NULL;



     int count = 0;



     printf("please input a string: \n");



     scanf("%s",str);

     

     while( ( ptr_t = strstr( str,ptr )) != NULL ){

         count += 1;

         ptr_t = ptr_t + 6;

         strcpy( str, ptr_t );

     }

     printf("pascal count is %d\n",count );



     return 0;



}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-6-17 23:35 , Processed in 0.075889 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表