what is segmentation fault?
What does segmentation fault mean?
Why when i run the following code, there is a segmentation fault?:
Code:
#include <string.h>
#include<iostream.h>
#include<fstream.h>
#include<ctype.h>
#include"lvp/vector.h"
int main()
{
// const int BUFF_SIZE=100000;
const long long BUFF_SIZE = 1000000;
int a;
ifstream infile;
ofstream outfile;
char buff[BUFF_SIZE];
// open the files
// infile.open("/misc/tmp/kddcup.data_10_percent.fresh");
infile.open("data.txt");
outfile.open("output.txt");
// make sure the files are open
if(!infile.is_open()){
cerr << "error opening input file";
return 1;
}
if(!outfile.is_open()){
cerr << "error opening output file";
return 1;
}
// loop until the end of the input file
for(a=0; !infile.eof();){
// read in one line
char *p;
char word[20] = "";
infile.getline(buff,200);
// infile.ignore(1);
p = strtok(buff,",");
for(int i=0; i<42; i++)
{
if(i==1)
{
strcpy(word,p);
cout<<word<<endl;
outfile << word << endl;
}
if(i==2)
{
strcpy(word,p);
cout<<word<<endl;
outfile << word << endl;
}
if(i==3)
{
strcpy(word,p);
cout<<word<<endl;
outfile << word << endl;
}
if(i==41)
{
strcpy(word,p);
cout<<word<<endl;
outfile << word << endl;
}
p = strtok(NULL,",");
}
}
// close the files
infile.close();
outfile.close();
// pause so you can see the output on the screen
cout << " **** All done! ****\n";
cin.get();
return 0;
}
Thanks for response,
~D