Hey there ,
I have a problem about saving information, which is read from a text file, to an char array.I have to read the file character by character.I could't use getline() function and string, I have to use get() function.There is a sample of the all data :
" Tsutsumi-Ishii,Y. Response of heat shock element within the human HSP70 promoter to mutated p53 genes 1995 Cell Growth Differ 6
Fraser,M. Akt promotes cisplatin resistance in human ovarian cancer cells through inhibition of p53 phosphorylation and nuclear function 2008 Int J Cancer 122
"
We have authors' names and some information about them.The purpose of this program ,
user is going to enter name of the author and we will show author's information on the screen.
I tried save the whole information in an char array like :
while(!fin.eof())
{ int count =0;
for(int i=0 ; i<5000 ; i++)
{ for(int j=0;j<1000; j++)
{ fin.get(array[i][j])
if(array[i][j] == '\n') break;
else continue;
}
}
}
However this does not store the data in array , when I tried to write array on screen out of the while , it crashed.I think it is about get method .I tried to call that method by reference, but did not work.
Finally I wrote a specific function about calling by reference , it is also not working.
I do not know where the problem. When my program is run, there is an error occurred , "main.exe has stopped working".
Here is my final code:
#include <iostream>
#include <fstream>
using namespace std;
char myfunc ( ifstream &fin_ref , char &c);
int main()
{
ifstream fin;
// open the file
fin.open("dataset.txt");
char array[5000][1000];
char input[10];
// if smth goes wrong about openning data
if(fin.fail())
cout<<"error"<<endl; return 0;
// take the author name
cout<<"enter the first 3 char of your author name please \n";
for(int t=0 ; t<10;t++)
cin>>input[t];
// set the whole data in multi dim. array.
char array1[1000];
char x;
for(int i=0 ; i<5000 ; i++)
{
for(int j =0 ; j<2000, array[i][j] != '#'; j++)
{
//fin.get((char *)& array , sizeof(array));
array[i][j] = myfunc(fin , x);
}
}
// close the file
fin.close();
int count =0; // check how many char is going to be equal.
for(int i=0 ; i<5000 ; i++)
{
for(int j =0 ; j<10; j++)
{ if(input[j] == array[i][j])
count = count +1;
}
if(count >= 3) // if more than or equals to tree char than we write the author info
for(int k =0 ; k<2000; k++) cout<<array[i][k];
}
cout<<endl;
return 0;
}
// we have to save the data in an array so we have to work with addresses.
char myfunc ( ifstream &fin_ref , char &c)
{
fin_ref>>c;
return c;
}
NEEEEEEDDDDDD HELLLPPPPPP !!! :))