string replace_strings (FILE *in, FILE *out, char *what, char *repl)
{
int x = strlen(what);
int z = strlen(repl);
string newWhat(what, x);
string newRepl(repl, z);
char c;
char *str; //наш буффер
int i = 0;
size_t found;
我知道这样做是一个错误的决定
while(!feof(in))
{
while((c!='\0') && (i<=255))
{
str[i] = fscanf(in, "%c", c);
i++;
}
string newStr (str, i);
while(found != string::npos)
{
found = newStr.find(newWhat);
newStr.replace(found, newWhat.length(), newRepl);
}
fprintf(out, "%s", newStr.c_str());
它返回段错误,出了什么问题?我应该怎么办?各位帮帮忙
最佳答案
您必须为str
分配内存。使用stringstream ,并忘记笨拙的缓冲区。
关于c++ - 是什么导致了这个段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19622699/