I am doing a homework assignment using pointers to traverse arrays. When I go to assign a 5 digit zip code to an array the array is populated with the ascii value of the number. I am having a hard time grasping the concept of pointers and when to use them.
I have used the debugging tool on eclipse to determine that the array is being populated incorrectly and not my output statement.
Here is the method used to populate the array where r1
is an object of a class and zipcode
is an integer array of size 5 (for loop only increments to five for testing purposes):
void getDataFromFile(RentalAgency &r1){
ifstream infile;
string input;
char number;
cout << "Enter the file name: ";
infile.open("Agencies.txt");
infile.get((r1.name),MAX_SIZE,space);
for(int i = 0;i < 5;i++){
infile >> number;
*(r1.zipcode+i) = number;
}
infile.close();
}
And here is the code for struct RentalAgency:
struct RentalAgency{
char name[MAX_SIZE];
int zipcode[5];
RentalCar inventory();
};
When given the number 93619 the expected output is 93619, however the actual output is 57 51 54 49 57