c++ - file pointer abrubtly points to eof. -


this program asks user string search , on finding asks replacement string , replaces string.when executing program , endlessly prints "inside while-1" new file operations in c++ , not able find soln. code.

#include <iostream> #include <fstream> #include <string.h> using namespace std;  int main() {  char line[50],str[50],rep[50],*a;  int len = 0; fstream f("file.txt",ios::out|ios::in); cout << "enter string searched" << endl; cin.getline(str,50,'\n');   //  cout << str << endl;  len = strlen(str); // f.seekg(0); while(!f.eof()) {      cout << "inside while" << f.tellg()<<endl;      f.getline(line,'\n');       = strstr(line,str);      if(a != null )      {          cout << "string found\n enter replacement string" << endl;          cin.getline(rep,'\n');          int i=0,j=0;          while(i < strlen(rep) )          {            a[i] = rep[i];            i++;          }          while(i < strlen(a))          {            a[i] = ' ';            i++;          }      } }  if(str == null)      {         cout << "no instance of string found" << endl;      } f.close();  } 

my file contains

there blood titanic saving private ryan skyfall 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -