In my program, the name of the file with the values (at most 2-digit numbers) to be read is given in the terminal and my main() is as below:
int main ( int argc, char *argv[] )
{
//assume argv[1] is a filename to open
ifstream the_file ( argv[1] )
if ( !the_file.is_open() ){
cout<<"Could not open file" << endl;
return 0;
}
char x;
int array[10];
int x_int;
while ( the_file.get ( x ) ){
for (int i=0; i<10;i++){
array[i] = (int)x;
}
}
}
However, I am getting some odd number.
My mistake is definitely at array[i] = (int)x;
line, but
how can I convert read char value to int? Or is there any other method to read them as int type?
I want to have the values taken from input file work as integers, not as a single digit
My actual input file (.txt) is:
75
95
1
2
45
65
98
6
7
9