如何找到字符串里的倒数第三个空格并且将那个空格后面的字符串替换为另一个字符串

如何找到字符串里的倒数第三个空格并且将那个空格后面的字符串替换为另一个字符串。

你可以从字符串尾部开始向前查找啊。找到空格后,修改其后面的字符串内容。

#include <stdio.h>
#include <string.h>
int main()
{
    char s[100],a[10];
    int i=0,count=0,j=0;
    gets(s);
    gets(a);
    i=strlen(s)-1;
    while(i>=0)
    {
        if(s[i] == ' ')
        {
            count++;
            if(count == 3)
            {
                do
                {
                    s[i+1]= a[j];
                    i++;
                }while(a[j++] != 0);
                break;
            }
        }
        i--;
    }
    printf("%s",s);
    return 0;
}