Замена символов?
char line[80];
char symb[3] = { '.','.','.'};
char symb1[1] = { '.' };
cout << "Input string : ";
cin.getline(line, 80);
for (int i = 0; i < strlen(line); i++)
{
if (line[i] == symb[3])
{
line[i] = symb1[0];
}
}
Как заменить (...) на . ,я вот сделал что-то не получилось , как исправить?
Ответы (2 шт):
Автор решения: n1tr0xs
→ Ссылка
Можно так:
#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
int main(){
char *line = new char[80];
cout << "Input string : ";
cin.getline(line, 80);
char *new_line = new char[80];
size_t i, j = 0;
bool flag = true;
for(i=0; i<strlen(line)-2; ++i){
if(line[i] == '.' && line[i]==line[i+1] && line[i]==line[i+2]){
new_line[j++] = '.';
flag = false;
}
else{
new_line[j++] = line[i];
flag = true;
}
}
if(flag)
while(i<strlen(line))
new_line[j++] = line[i++];
cout << new_line << '\n';
delete[] line;
delete[] new_line;
return 0;
}
Автор решения: Harry
→ Ссылка
Ну, я бы делал (на функции C запрета же нет?)
char* delEll(char * buf)
{
for(char * s = strstr(buf,"..."); s; s = strstr(s,"..."))
memmove(s,s+2,strlen(s+2)+1);
return buf;
}
:)