Замена символа в произвольном тексте с использованием функций библиотеки string.h
По условиям лабораторной работы нельзя использовать методы класса string. Необходимо использовать функции библиотеки string.h!
Задача: в произвольном тексте в словах с указанными номерами заменить заданную букву на другую заданную букву пользователем. Не знаю как сделать замену одного символа на другой, и пока не до конца понимаю правильно ли я решаю задачу. код:
#include <iostream>
#include "string.h"
#include "stdio.h"
using namespace std;
int main()
{
char from, to;
char text[100],*wbeg, * wend, delim[] = " ;:,.?!";
cout << "Input text and put '.' at the end: "; cin.getline(text, 100, '.');
do { cout << "Line is empty! Retry: "; cin.getline(text, 100, '.');} while (strlen(text) == 0);
int n_delim = strspn(text, delim); // возвращает к-сть разделителей
wbeg = text + n_delim; // указатель на начало слова
wend = text + strlen(text); // указатель на конец слова
n_delim = strcspn(wbeg, delim);//длина первого слова
int count = 1; cout << "Input number of thе word: "; int number; cin >> number;
while ((wbeg + n_delim <= wend) && (n_delim != 0))
if (count == number)
{
do
{
cout << "Input symbol, that should be changed: "; char ch1; cin >> ch1; //запрос буквы
char *pos_s = strchr(wbeg, ch1);
if (pos_s == 0) cout << "No symbol!";
else if (wbeg + n_delim <= pos_s)
cout << "Input symbol to change one: "; char ch2; cin >> ch2;
ch2 = &pos_s;
} while (count <= number);
}
else cout << "No words with given number!"; return 0;
}
return 0;
}