Home > Blockchain >  why does character_arrays.exe has stopped working error pop up?
why does character_arrays.exe has stopped working error pop up?

Time:04-12

my code is working fine. Its showing the right results in the file but after executing the code,an error message pops up saying "character_array.exe has stopped working". Can anyone tell why that error appears??

#include <iostream>
#include<cstring>
#include<fstream>
#include<string>
using namespace std;

int main()
{
    string name[20], roll_no[20];
    int price[20], k=0;
  ifstream data;
  ofstream dout;
  char fname[4];
  char fname1[]={"dout"};
  cout<<"enter file name : ";
  cin.getline(fname, 20);
  if(strcmp(fname,fname1) !=0)
  {
      cout<<"file names do not match";
  }
  else{
  data.open("new.txt");
  while(!data.eof())
  {
      for(int i=0; i<20; i  )
      {
          data>>name[i]>>roll_no[i]>>price[i];
          k  ;
      }
  }
  data.close();
   cout<<"data in the text file is:"<<endl;
  for(int i=0; i<6; i  )
  {
     cout<<name[i]<<"  "<<roll_no[i]<<"  "<<price[i]<<endl;
  }

  dout.open("output.txt");
  for(int i=0; i<6; i  )
  {
      dout<<name[i]<<"  "<<roll_no[i]<<"  "<<price[i]<<endl;
  }
  }

return 0;
}

CodePudding user response:

I am assuming that your issue is an infinite loop, if your IDE supports breakpoints, I would recommend adding one to your while loop and seeing if it runs forever.

  • Related