I have an input.txt file, I am trying to read input file by line and I want to compose 2 arrays. First line after space gives the size of the array. Size of the array is 3 for my example input file which is below. From second line after first space till end of the file composes array A[]. For this example A[3]={5,8,14} From Second line after second space till end of the input file composes content of array B[]. It is B[3]={67,46,23} for this input file. After first line first numbers of every line is just gives the line number of each line.Input file is like that:
10 3
1 5 67
2 8 46
3 14 23
Here is the below my start code. How can I get the second and last characters of a line for an input file?
#include<stdio.h>
#define N 128
#include <iostream>
#include <fstream>
int A[N];
int B[N];
int main(){
ifstream fin;
fin.open("input.txt", ios::in);
char CHARACTER;
int ITEMNUMBER = 0;
while (!fin.eof() ) {
fin.get(CHARACTER);
if (CHARACTER== '\n'){
++ITEMNUMBER;
}
}
printf("\n");
cout << "NUMBER OF ITEMS: " << ITEMNUMBER<< endl;
return 0;
}