How would I use the endptr to figure out where it went wrong? Also Daved I made sure to add the /0 but that didn't help.
Heres my full function including my structure I am using.
Code:
struct Acc_var{
float Acc_Balance;
long int Acc_Number;
char Name[25];
};
int LoadDataFromFile(Acc_var *Accounts){
int x=0,start=0,z=0;
int x1;
int count=0;
char buff[880];//Only needs 880 for the buffer
char A[10];
ifstream Atmfile;
Atmfile.open ("Atm.txt");
if (Atmfile.fail()) {
cout<<"Couldn't open Atm.txt\n";
return -1;
}
else{
while (!Atmfile.eof() )
{
buff[x]=Atmfile.get();//Grabs anything in the file including whitespaces
if(buff[x]=='\n'){//Gets ride of the new lines
buff[x]=Atmfile.get();
}
cout<<x<<' '<<buff[x]<<endl;//Shows what is inputed into the buffer and what space in the buffer
x++;
}
}
cout<<endl<<endl<<endl;
x=0;
for(count=0; count<3; count++){//as a test run only runs 3 times
for(int N=start; N<start+24; N++){//Start is where the loop ended last
Accounts->Name[N]=buff[N];//Puts the charaters from the buffer into Name
x++;
}
x+=3;//moves through 3 whitespaces
cout<<x<<endl;//Says its 27
x1=x;
for(z=x; z<start+33; z++){//Loops 5 times
A[z]=buff[z];//Grabs the 5 numbers from the buffer file and puts them into A[10];
cout<<A[z]<<' '<<buff[z]<<endl;//Couts that they are fine
if(z==5+x1){//At the 5th loop it SHOULD convert the array in A[10] to an int but it is display 0's for some reason.
cout<<"A:"<<atoi(A)<<endl;
Accounts->Acc_Number=atoi(A);
cout<<Accounts->Acc_Number;
}
x++;
}
x+=3;
cout<<x<<endl;
for(int r=z; r<start+44; r++){
Accounts->Acc_Balance=buff[x];
x++;
}
start=x;
Accounts++;
}
Atmfile.close();
return 0;
}
This is my text file
Code:
Iwan Bodnarchuk 12345 000000100
Bobby McGavier 54321 100000000
And this is what my output is:
x:27
A[z]=1 buff[z]=1
A[z]=2 buff[z]=2
A[z]=3 buff[z]=3
A[z]=4 buff[z]=4
A[z]=5 buff[z]=5
A(Atoi)=0