I am coding a class ArrowsCounting which implements a method
LineAccounterT(const char * archivos2[]). It should return the Number of arrows in a file.
It work fine if the Size of archivos2 <18 but for SizeArchiv2>18
the Program received signal " “EXEC_BAD_ACCESS" segmengation fault.
class ArrowsCounting flecha[SizeArchiv2];
int SizeArchiv2;
//! Files to be processed
archivos2[]={"/Users/mprez/Desktop/kit_programm/AAPL_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/AA_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ABC_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ABT_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ACE1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ACINF_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ADBE_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ADI_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ADM_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ADP_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/ADSK_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/AEE_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/AEP_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/AES_1996bis2009.txt ",
" /Users/mprez/Desktop/kit_programm/AET_1996bis2009.txt ",
}
//! It calculates the Number of Files to be edited
SizeArchiv2=sizeof(archivos2)/sizeof( constchar*);
//!Because i need the Number of lines for a serie of files, i did define the
int Js_Size[SizeArchiv2];// such as an Array of Number of Lines in the Files "archivos"
//!######################################
//!--------->Lines in Files<-------------
//!######################################
for (int k=0; k<SizeArchiv2;k++)
{
Js_Size[k]=flecha[k].LineAccounterT(archivos2);
}
There are many things wrong with that program.
First, rawFiles is a pointer to a pointer to const char. SizeArchiv2 will always be 1. Pass a string vector instead.
Second, the size of an array must be a constant known at compile-time. You cannot use SizeArchiv2 as the size. Again, use vector. Or in this particular case, get rid of myfiles entirely - there's no point in keeping the old fstream objects.
Third, your condition in the while loop will cause problems on some implementations. You should write while (!getline(...)) instead.
Edit: and fourth, you cannot compare char pointers (well, you can, but it certainly won't do what you want to). Use string.