#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
FILE *input = stdin;
FILE *output = stdout;
char buffer[512];
while (fgets(buffer
, sizeof(buffer
), input
) != NULL
) {
/* The text to find */
static const char text_to_find[] = "xyz";
/* The text to replace it with */
static const char text_to_replace[] = "abc";
char *pos
= strstr(buffer
, text_to_find
); if (pos != NULL)
{
/* Allocate memory for temporary buffer */
/* Copy the text before the text to replace */
memcpy(temp
, buffer
, pos
- buffer
);
/* Copy in the replacement text */
memcpy(temp
+ (pos
- buffer
), text_to_replace
, strlen(text_to_replace
));
/* Copy the remaining text from after the replace text */
1 + strlen(buffer
) - ((pos
- buffer
) + strlen(text_to_find
)));
}
else
}
return 0;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50IG1haW4oKQp7CiAgICBGSUxFICppbnB1dCA9IHN0ZGluOwogICAgRklMRSAqb3V0cHV0ID0gc3Rkb3V0OwoKICAgIGNoYXIgYnVmZmVyWzUxMl07CiAgICB3aGlsZSAoZmdldHMoYnVmZmVyLCBzaXplb2YoYnVmZmVyKSwgaW5wdXQpICE9IE5VTEwpCiAgICB7CiAgICAgICAgLyogVGhlIHRleHQgdG8gZmluZCAqLwogICAgICAgIHN0YXRpYyBjb25zdCBjaGFyIHRleHRfdG9fZmluZFtdID0gInh5eiI7CgogICAgICAgIC8qIFRoZSB0ZXh0IHRvIHJlcGxhY2UgaXQgd2l0aCAqLwogICAgICAgIHN0YXRpYyBjb25zdCBjaGFyIHRleHRfdG9fcmVwbGFjZVtdID0gImFiYyI7CgogICAgICAgIGNoYXIgKnBvcyA9IHN0cnN0cihidWZmZXIsIHRleHRfdG9fZmluZCk7CiAgICAgICAgaWYgKHBvcyAhPSBOVUxMKQogICAgICAgIHsKICAgICAgICAgICAgLyogQWxsb2NhdGUgbWVtb3J5IGZvciB0ZW1wb3JhcnkgYnVmZmVyICovCiAgICAgICAgICAgIGNoYXIgKnRlbXAgPSBjYWxsb2MoCiAgICAgICAgICAgICAgICBzdHJsZW4oYnVmZmVyKSAtIHN0cmxlbih0ZXh0X3RvX2ZpbmQpICsgc3RybGVuKHRleHRfdG9fcmVwbGFjZSkgKyAxLCAxKTsKCiAgICAgICAgICAgIC8qIENvcHkgdGhlIHRleHQgYmVmb3JlIHRoZSB0ZXh0IHRvIHJlcGxhY2UgKi8KICAgICAgICAgICAgbWVtY3B5KHRlbXAsIGJ1ZmZlciwgcG9zIC0gYnVmZmVyKTsKCiAgICAgICAgICAgIC8qIENvcHkgaW4gdGhlIHJlcGxhY2VtZW50IHRleHQgKi8KICAgICAgICAgICAgbWVtY3B5KHRlbXAgKyAocG9zIC0gYnVmZmVyKSwgdGV4dF90b19yZXBsYWNlLCBzdHJsZW4odGV4dF90b19yZXBsYWNlKSk7CgogICAgICAgICAgICAvKiBDb3B5IHRoZSByZW1haW5pbmcgdGV4dCBmcm9tIGFmdGVyIHRoZSByZXBsYWNlIHRleHQgKi8KICAgICAgICAgICAgbWVtY3B5KHRlbXAgKyAocG9zIC0gYnVmZmVyKSArIHN0cmxlbih0ZXh0X3RvX3JlcGxhY2UpLAogICAgICAgICAgICAgICAgICAgcG9zICsgc3RybGVuKHRleHRfdG9fZmluZCksCiAgICAgICAgICAgICAgICAgICAxICsgc3RybGVuKGJ1ZmZlcikgLSAoKHBvcyAtIGJ1ZmZlcikgKyBzdHJsZW4odGV4dF90b19maW5kKSkpOwoKICAgICAgICAgICAgZnB1dHModGVtcCwgb3V0cHV0KTsKCiAgICAgICAgICAgIGZyZWUodGVtcCk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICAgICAgZnB1dHMoYnVmZmVyLCBvdXRwdXQpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==