在数组中查找字符串的位置

如何在字符串中查找指定字符位置?

       

#include<stdio.h>

void main()
{
    char buf[]="214wqefxcvdfgerh3gfdh23wer1234e";
    cha sub[]="1234";
       int i=0;
    while(buf[i]!='\0')
    {
        if(sub[0]==buf[i])
        {
            x=1;
            while(sub[x]==buf[i+x] && sub[x]!='\0')    x++;
                if(4==x)
                {
                    printf("存在%s的字符串,它的位置是%d",sub,i);
                        return;
                }
        }
        i++;
    }
    printf("不存在字符串%s\n",sub);
}

猜你喜欢

转载自blog.csdn.net/cs13797778767/article/details/81087381
今日推荐